1
Computer Lab
-
Practical Question Bank
FACULTY OF COMMERCE, OSMANIA UNIVERSITY
----------------------------------------------------------------------------------------------------------
B.Com
(Computer & Computer Applications) III Year
W.E.F.2010
-
11
FUN
DAMENTALS OF JAVA
Time: 60 Minutes
Record
:
10
Skill Test
:
20
Total Marks
:
30
1.
Write a program to demonstrate
the concept of Encapsulation.
2.
Write a program to demonstrate
the concept of Inheritance and polymorphism through
ove
rloading and overriding
3.
Write a program to define a class
Employee
with a constructor to keep track of the number
of objects of type
Employee
created. (Use a counter in the constructor)
4.
Write a program to display the following output using a single
print
s
tatement
Commerce= 99
Economics= 90
Maths= 100
5.
Using JOptionPane class
in the swing package
, w
rite a program to read two numbers from
the keyboard
through the InputDialogs
and display larger value on the screen
in a message
dialog.
6.
Write a program to c
onvert given number of days into months and days.
7.
Write a program to display details of student based on average as shown below
a.
If average is greater than or equal to 60
----
print first class
b.
If average is greater than or equal to 50 and less than 60
----
print second class
c.
If average is greater than or equal to 35 and less than 50
----
print third class
d.
If average is less than 35
-----
print failed.
Use Swing Package’s JOptionPane to take the inputs and show the resultant class.
8.
Write a program that request
s two float type numbers from the user divide the first by the
second and display the result along with the numbers.
Use JOptionPane class of the swing
package.
9.
Write a
java
program to
demonstrate the concepts of pass by value and pass by reference.
10.
Write
a java program with a class that has a method called
swap(int a, int b)
that takes in
two arguments and swaps the contents of each other.
Use call by reference to achieve actual
swapping.
11.
Write a
java
program
with a class which has the following members
Methods
getSimpleInterest( )
getCompoundInterest( )
Variables
P
–
Principal
r
–
Rate of Interest
n
–
No. of years
.
2
12.
Write a java program with a class that input string as a member with the following methods;
getInputString()
–
To display the str
ing
getReverseString()
–
To display the reverse of the string
getLength()
–
To find out the length of the string.
13.
Write a
java program with a class
Matrix
for representing a 2
-
dimensional integer matrix
along with a few operations. The class should have
the following members
Variables:
2
-
dimensinal Array A[][]
Methods:
getNonZeroElements
()
–
To print all the non
-
zero elements of the array
getElement(int row, int col)
–
To get the
element at the position of A[row][col]. Handle
the
IndexOutOfBoundsExce
ption
for the arguments row and col
14.
For the above method add another method
getSumofElements( )
–
get the sum of all the elements of the array.
getAverage(
)
-
get the average of all the elements of the array.
15.
Add another method to the above class
to
find
the standard deviation
of all the elements of an
integer array
getStdDev()
.
16.
Write a java applet program that accepts the coordinates of two points and draw a line
between the two points The point is represented by the coordinates (x,y).
17.
Add a method
to the
Matrix
class to display
the elements of a 2
-
dimensional array in the
form of a matrix.
18.
Write a
java class
Fibonacci
with a method
to
print the 1
st
k
numbers in the Fibonacci series.
Note:
( f(n) = f(n
-
1) + f(n
-
2)
Fibonacci series is 1,1,2,3,5,8
,13,21…….)
19.
Write a program to input “
n”
numbers and find the number of +ve and
–
ve numbers in the
inputted numbers.
20.
Add a method to the
Matrix
class
to add two matrices and output the resultant
matrix.
21.
Add a method to the
Matrix
class to
search for a given
input element in the matrix and return
true or false based on the search.
boolean
Search
(int element)
22.
Write a program to accept the marks of 10 students and display their grades based on the
following criterion
Range
Grade
< 40
F
40
-
50
D
50
-
60
C
60
-
70
B
> 70
A
23.
Write a program to
find the sum of the 1
st
N natural numbers given the input N.
Implement in
the form a method of a java class.
24.
Write a program to input the profits of a company for the last 10 years. Find the maximum,
minimum and the avera
ge profit attained during this tenure.
Implement methods for finding
each of them.
3
25.
Write a program to input the total amount of profit from the keyboard and find the amount of
profit to be distributed to three partners with profit sharing ratio of 2:3:5.
26.
W
rite a program to compute the income tax payable given the amount of taxable income as
input from the keyboard.
Assume the following slab rates of tax
Income
Rate
0
-
1,60,000
Nil
1,60,000
-
3,00,000
10%
3,00,000
-
5,00,000
20%
>5,00,000
30%
27.
Write a program by switch statement to
a.
Print “hai” if entered one
b.
Print “hello” if entered two
c.
Print “how are you” if entered three
d.
Print “bye” if any other number.
28.
Write a
java class
Number
with the following members
A positive intege
r number
num
29.
Add a method to the
Number
class to display all the 1
st
n multiples of the given number
getFirstNMultiples
(int n )
30.
Add a method to the Number class to
display
all the
factors of a given number
.
getFactors( )
31.
Write a user define
d exception that extends the
Exception
class
an
d handles the
D
ivideB
yZero
Exception.
32.
Write a
java applet that accepts the size of a square and fill it with red color.
33.
Add a method to the
Number
to
find
the
factorial of a given number
.
34.
Add a met
hod to the
Number
class to
check
whether
the
given number is prime
or not.
35.
Write a java program to extend the
Thread
class with two threads running in parallel one to
print the numbers and the other to print the alphabets.
36.
Write a java class that e
xtends the
Thread
class which calculates the sum of all the 1
st
50
even natural numbers.
37.
Write a program to display the following figure
*
* *
* * *
* * * *
38.
Write a program to display a larger number among two numbers
using conditional operator.
39.
Write a program to output the
Cost of Production
given the following inputs
No. of units of goods manufactured
Variable Cost per unit
Fixed Cost of Production
Wages
4
40.
Write a program Input 10 numbers through keyboard into
an array and find if a given input
number to be searched is present in the array.
41.
Write a program to convert a given input sum of money in rupees to foreign currency in
terms of
US dollars,
Australian Dollars,
Dinar
Pounds
Assume the current excha
nge rates.
42.
Define a structure,
student
which contains student name, age, marks.
Using this structure write a program to read this information for one person from keyboard
and print the same on the screen.
43.
Write a java program with a class and a me
thod which finds if a given inpu
t number is
divisible by 2,3,5
and returns true or false.
44.
Write a program to declare a class
Company
with members Company Name, No. of
employees, date of Incorporation, List of Directors (Array of strings)
45.
Write a ja
va interface
Quadrilateral
and two classes
Rectangle
and S
quare
that derive from
the
Quadrilatera
l class.
46.
Write two methods for finding the area and perimeter of a
Quadrilateral
and Implement the
methods for the derived classes
Rectangle
and
Square
.
47
.
Define a
Employee
class with the members EmpId, FirstName, MiddleName, LastName,
Age, Salary and a constructor which takes the EmpId as argument. Write a program to
declare two objects of type
Employee
class.
48.
Define a class
Rectangle
with two members
length and breadth as integers. Define two
constructors one which takes a single argument (Square) and the other which takes 2
arguments (Rectangle). Declare two objects using both the constructors
49.
Define a class
PartnershipFirm
with the members Firm
Name, Capital, No. of members,
Type of business. Define a constructor and destructor for the class to keep track of the no. of
objects of type
PartnershipFirm
that are present
Hint: Use increment, decrement operators in the constructors, destructors respe
ctively.
50.
Write a program to demonstrate
some of the string
functions.
Use functions in both the class
String
and
StringBuffer.
*****
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Comments 0
Log in to post a comment