Professional Documents
Culture Documents
Assignment 1
Assignment 1
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:
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
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.
8. Write a program to declare a stack and perform push and pop operation using stack class.
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.
10. Create a person inherit two classes from it politician & sportsman provide constructors &
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
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).
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.
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 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
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.
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
Q10 Write a program to add elements to the HashMap given the key and value data type is String?