Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Assignment 1

1. Write a Java program to find the factorial of a number.

2. Write a java program which initialization earning of an employee. The program should

calculate the income tax to be paid by the employee as per the criteria given below:

Slab rate IT rate

Upto Rs. 50,000 Nil

Upto Rs. 60,000 10% on additional amount

Upto Rs. 1,50,000 20% on additional amount

Above Rs. 1,50,000 30% on additional amount

Hint: - Run: - java calculates 1,25,000

Result: - income tax is …………………………….

3 Write a program to input n numbers on command line argument and calculate maximum of

them.

4 Write a program to print the sum and average of the even and odd numbers separately

given on command line argument.

5 Write a program to print the following pattern given n as argument:- [for input 3]

2 2

3 3 3

6. Design a class for a bank database the database should support the following operations.

1. Deposit a certain amount into an account,

2. Withdrawing a certain amount from an account,


3. Return a value specifying the amount (i.e. balance) in an amount.

7 Define a “Clock” class that does the following: -

a. Accept hours, minutes and seconds.

b. Check the validity numbers.

c. Set the time to AM/PM mode.

Use necessary constructors and methods to do the above task.

8. Write a program to declare a stack and perform push and pop operation using stack class.

9. Write method of date class to support the following:-

a.Method for validating that the integer-representing month is between 1 & 12 and checking

that the day part of the date objects is within the correct range for a month.

b.Obtaining the next day from a given date.

10. Create a person inherit two classes from it politician & sportsman provide constructors &

calculate salary & display functions.


Assignment 2

1. Create a class with a method that prints "This is parent class" and its subclass with another method that prints
"This is child class". Now, create an object for each of the class and call

1 - method of parent class by object of parent class

2 - method of child class by object of child class

3 - method of parent class by object of child class

2. In the above example, declare the method of the parent class as private and then repeat the first two operations
(You will get error in the third).

3. Create a class named 'Member' having the following members:

Data members

1 - Name

2 - Age

3 - Phone number

4 - Address

5 - Salary

It also has a method named 'printSalary' which prints the salary of the members.

Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data
members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to
an employee and a manager by making an object of both of these classes and print the same.

4. Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two methods to print the area
and perimeter of the rectangle respectively. Its constructor having parameters for length and breadth is used to
initialize length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with its constructor
having a parameter for its side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and
perimeter of a rectangle and a square.

5. Now repeat the above example to print the area of 10 squares.

Hint-Use array of objects

6. Create a class named 'Shape' with a method to print "This is This is shape". Then create two other classes named
'Rectangle', 'Circle' inheriting the Shape class, both having a method to print "This is rectangular shape" and "This is
circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a method to print "Square is a
rectangle". Now call the method of 'Shape' and 'Rectangle' class by the object of 'Square' class.
Assignment 3

Exercise 1: Create a package with name “First” with class as “One” and declare a method with name “show” and
display a console statement “inside first package”. Create one more package with name “Second” with class as
“Two” and declare main method and call the message “show” of “One” class.

Exercise 2: For the exercise 1 try and test with all the access modifiers and draw a chart what happens when
1. Same package sub class
2. Same package non-sub class
3. Different package sub class
4. Different package non-sub class

Exercise 3: In reference to exercise 1, create a sub package under “First” with name “First_Senior” with class as
“Three” and declare a method with name “show” and display a console statement “inside first_Senior package”.
Now through class s “Two” again call the message “show” of “Three” class.

Exercise 4: Write a java program to illustrate how to declare, instantiate, initialize, and traverse the Java array.

Exercise 5: Write a program to print the array elements using for-each loop

Exercise 6: Write a program to demonstrate the way of passing an array to method.

Exercise 7: Write a java program for method overloading

Exercise 8: Write a java program for method overriding

Exercise 9: Write a program to illustrate compile- time polymorphism in java

Exercise 10: Write a program to illustrate run- time polymorphism in java by creating one superclass Animal and
three subclasses, Herbivores, Carnivores and Omnivores. Subclasses extend the superclass and override its eat()
method. We will call the eat() method by the reference variable of  Parent class, i.e. Animal class. As it refers to the
base class object and the base class method overrides the superclass method, the base class method is invoked at
runtime.

Exercise 11: Create a class with a method that prints "This is parent class" and its subclass with another method that
prints "This is child class". Now, create an object for each of the class and call

1 - method of parent class by object of parent class

2 - method of child class by object of child class


3 - method of parent class by object of child class

Exercise 12: Create a class named 'Member' having the following members:

Data members

1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method named 'printSalary' which prints the salary of the members.

Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data
members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to
an employee and a manager by making an object of both classes and print the same.

Exercise 13: Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two methods to print
the area and perimeter of the rectangle respectively. Its constructor having parameters for length and breadth is used
to initialize length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with its constructor
having a parameter for its side (suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and
perimeter of a rectangle and a square.

Exercise 14. Now repeat the exercise 7 to print the area of 10 squares.

Hint-Use array of objects.

Assignment 4

Users want to book hotel. For the same they must sign up with Name, age, id, and password which shall be stored in
file. As soon as users sign in, their id and password shall be verified first, after successful sign in user selects city
(fetch from files) and dates which shows him list of all hotels in the city with availability and prices. When user
selects any hotel, System ask him for more details like number of rooms, number of persons, name, and age of every
person, system also ask that whether he is one of the travelers or not, if yes then his details are automatically
included in the traveler list (use inheritance). Finally, system generates bill for the booking with unique booking Id
and a discount of Rs. 1000 if net amount exceeds Rs. 10000. (use Exception handling for wrong inputs).

Assignment 5

Q1. Write a program to traverse (or iterate) ArrayList?

Q2 Write a program to convert List to Array. 

Q3 Write a program to traverse (or iterate) HashSet? 

Q4 Given an element write a program to check if element(value) exists in ArrayList?


Q5 Given an element write a program to check if element exists in HashSet?

Q6 Write a program to initialize a HashMap in java?

Q7 Write a program to initialize an ArrayList in java?

Q8 Write a program to convert Array to List? 

Q9 Write a program to find the length of the ArrayList? 

Q10 Write a program to add elements to the HashMap given the key and value data type is String?

Q11 Write a program to initialize a HashSet in java?

Q12 Write a program to add elements to ArrayList ?

Q13 Write a program to add elements to HashSet? 

Q14 Write a program to get size of HashMap? 

Q15 How to check if HashMap is empty? 

You might also like