Lab Assignment, MCAP 1211, 2019
Lab Assignment, MCAP 1211, 2019
…..
…..
Day 5 (Inheritance)
1. Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and
Square. Use Quadrilateral as the super class of the hierarchy. The instance variables of
Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. Write
a program that instantiates objects of your classes and outputs each object's area (except
Quadrilateral).
2. Write a program to create a class named Vehicle having protected instance variables regnNumber,
speed, color, ownerName and a method showData ( ) to show “This is a vehicle class”. Inherit the
Vehicle class into subclasses named Bus and Car having individual private instance variables
routeNumber in Bus and manufacturerName in Car and both of them having showData ( ) method
showing all details of Bus and Car respectively with content of the super class’s showData ( )
method.
Day 6 (Interface)
1. Create an interface Department containing attributes deptName and deptHead. It also has abstract
methods for printing the attributes. Create a class hostel containing hostelName, hostelLocation
and numberOfRooms. The class contains method printing the attributes. Then write Student class
extending the Hostel class and implementing the Department interface. This class contains
attributes studentName, regdNo, electiveSubject and avgMarks. Write suitable printData method
for this class. Also implement the abstract methods of the Department interface. Write a driver
class to test the Student class. The program should be menu driven containing the options:
i) Admit new student ii) Migrate a student iii) Display details of a student
For the third option a search is to be made on the basis of the entered registration number.
2. Create three interfaces, each with two methods. Inherit a new interface from the three, adding a
new method. Create a class by implementing the new interface and also inheriting from a concrete
class. Now write four methods, each of which takes one of the four interfaces as an argument. In
main( ), create an object of your class and pass it to each of the methods.
Day 7 (Package)
1. Create a package containing classes that define all input / output methods. Use this package
for input / output operations in all the subsequent programs.
2. Complete the following:
a. Create a package named org.shapes.
b. Create some classes in the package representing some common geometric shapes like
Square, Triangle, Circle and so on. The classes should contain area and perimeter
methods in them.
c. Compile the package.
d. Use this package to find area and perimeter of different shapes as chosen by the user.
Day 9 (Multithreading)
1. Write multithreaded program that continuously prints the strings “ping” and “PONG” in the
console at random distances at intervals of one second. Use two threads one for “ping” and
another for “PONG”.
2. Write a program to sort a list of strings using multithreading. Create one of the threads that
take a string as input from the user, another thread that sorts the strings and finally another
thread that displays the sorted list of strings.