Java Assignments
Java Assignments
Day 1
1)
2)
3)
4)
5)
6)
Day 2
1) Create a class room which will hold the height, width and breadth of the room
in three variables. Create another class roomdemo which will use the earlier
class, create instances of rooms, set the values of the variables and would
calculate the volume of room. [Hint: Have main in the 2 nd class and save the file
in the 2nd class name.]
2) Write a program to implement a class student with the following members.
i. Name of the student
ii. Marks of the student
iii. Function to assign initial values
iv. Function to compute total average
v. Function to display the data
Write an appropriate main() to demonstrate the functioning of the above.
3) Declare a class bank account with the following:
i. Account Holders Name
ii. Account Number
iii. Account Type (S for savings and C for Current)
iv. Balance amount
Functions:
i. Initialize data
ii. Deposit money
iii.
Withdrawal of money minimum deposit Rs. 1,000/iv. To display all items
Write an appropriate main() to run it.
4) Create a class box whose constructor function is passed three double values,
which represent the length of the sides of the box. Have the box class compute the
volume and store the result in a double variable. Include a member function vol()
that displays the volume of the box.
Day 3
1) Create a generic base class called vehicle that stores number of wheels and speed.
Create the following derived classes:
Car that inherits vehicle and also stores number of passengers.
Truck that inherits vehicle and also stores the load limit.
Write a main() function to create objects of these classes and display all the information
about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and
display faster or slower if Car is faster or slower than Truck.
2) Create a base class called Building that stores the number of floors, the number of
rooms, and the total area in square feet.
Create a derived class called House that inherits Building and also stores
number of bedrooms bathrooms.
Create another derived class called office that inherits Building and also
stores the number of chairs, tables and telephones.
Write a main() function to declare one object of each of the classes mentioned and find i)
Area of the building and ii) which object has the smallest area.
3) Write a program that creates a base class called Number. This class holds an integer
value and contains a virtual function called displayNum(). Create two derived classes
called HexNum and OctalNum that inherit Number. Override displayNum() in the
derived classes so that it displays the value in Hexadecimal and Octal, respectively. Write
a main() function to create objects of type HexNum and OctalNum classes and
display the hexadecimal and octal form of the supplied integer value. Note: Use base
class object to call a function.
4) Write a program that creates a base class called Distance. It stores the distance between
two points in a double value variable and contain a virtual function called travelTime()
that outputs the time it takes to travel that distance, assuming that the distance is in miles
and the speed is 60 miles per hour. In a derived class called DistMKS, override
travelTime() so that it outputs the travel time assuming that the distance is in kilometers
and the speed is 100 kilometers per hour. Note: Use base class object to call a function.
5) Create a generic base class called 2Dfigure that holds two dimensions of a figure. It
also declares an abstract function called calculateArea() that, when overridden by derived
classes, returns the area of the type of 2D figure defined by the derived class. Create two
derived classes, Rectangle and Triangle that inherit 2Dfigure. Write a main()
function to create object of these classes and display the area of rectangle and triangle.
Note: Use base class object to call a function.
Day 4
1) Develop an abstract class GeometricObject which will have two variables colour and
weight.it would have constructor function for setting the colour as white and the weight
as 1.0 as default values. The class should have methods getColour() and getWeight() to
return the colour and weight values to the caller. The class should have two abstract
methods findArea() and findCircumference().
2) Write a subclass for GeometricObject called Triangle which will be able to calculate
area and circumference for a triangle.