You are on page 1of 3

HERITAGE INSTITUTE OF TECHNOLOGY

COMPUTER APPLICATION CENTRE

Assignment for Object Oriented Programming Lab (MCAP 1211)


MCA 1st Year 2nd Semester, Session: 2018-2019

Day 1 (Java Language Features)


1. A set of two linear equations with two unknowns x1 and x2 is given below:
ax1 + bx2 = m
cx1 + dx2 = n
The set has a unique solution:
x1 = (md – bn ) / ( ad – bc )
x2 = ( na – mc ) / (ad – bc)
provided the denominator ad- bc ≠ 0 .Write a program that will read the values of constants a, b, c,
d ,m and n and computes the values of x1 & x2.An appropriate message should be printed when
(ad-bc)=0.
2. For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency
is given by:
Frequency = √ [( 1 / LC ) – ( R2/4C2 )]
It is desired to study the variations of the frequency with C (capacitance). Write a program to
calculate the frequency of difference values of C starting 0.01 to 0.1 in steps of 0.01.

Day 2 (Arrays in Java)


1. Given are two one-dimensional arrays A & B, which are sorted in ascending order. Write a
program to merge them into single sorted array C that contains every item from arrays. A & B, in
ascending order.

2. The annual examination results of 100 students are tabulated as follows:


Roll No. Subject 1 Subject 2 Subject 3

…..
…..

Write a program to read the data and determine the following:


(a) Total marks obtain by each student
(b) The highest marks in each subject and the roll no of the student who secured it
(c) The student who obtained the highest total marks

Day 3 (String Handling)


1. Write a program that takes a String from the user on the command-line and print it in reverse.
2. Write a program to accept a string from the user and find out the following statistics:
(a) Count of uppercase character
(b) Count of lowercase character
(c) Count of digits
(d) Count of spaces
Day 4 (Classes and Objects)
1. Create a class called Time, which has three instance variables – hour, min and sec. It contains a
method called add ( ) which takes one Time object as parameter and print the added value of the
calling Time object and passed Time object. In the main method, declare two Time objects and
assign values using constructor and call the add ( ) method.
2. Create a class Stack that declares a stack and the methods to perform push ( ), pop ( ) and
checkEmpty ( ) operations on the stack. Create two stacks and write a menu-driven program to
perform operations on the two stacks. Whenever the number of elements in the two stacks
becomes equal, a message should automatically be generated displaying the number of elements
in each stack.

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 8 (Exception Handling)


1. Write a program called Factorial.java that computes factorials and catches the result in an
array of type long for reuse. The long type of variable has its own range. For example 20! Is
as high as the range of long type. So check the argument passed and “throw an exception”, if
it is too big or too small. If x is less than 0 throw an IllegalArgumentException with a
message
“Value of x must be positive”. If x is above the length of the array throw an
IllegalArgumentException with a message “Result will overflow”. Here x is the value for
which we want to find the factorial.
2. Define an exception called “NoMatchFoundException” that is thrown when a string is not
equal to “University”. Write a program that uses this exception.

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.

Day 10 (java.util and java.lang)


1. Write a java application that behaves like a malicious program in the sense that, whenever the
application is executed, it keeps on invoking the “NOTEPAD”, once in every second.
2. Write a program to implement a stack using the built-in Stack class of Java.

You might also like