You are on page 1of 4

HERITAGE INSTITUTE OF TECHNOLOGY

Master of Computer Applications


Object Oriented Programming Lab(MCAP 2111)
MCA 2nd Year 1st Semester, Session: 2020

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. An election is contested by 5 candidates. The candidates are numbered 1-5 and the voting is done
by marking the candidate number on the ballot paper. Write a program to read the ballots and
count the votes casts for each candidate using an array variable count. In case, a number read is
outside the range 1 – 5, the ballot should be considered as a ‘spoilt ballot’ and the program
should also count the number of spoilt ballot.

2. Write a program to find the elements, a [i, j] in a two-dimensional array which are maximum
element to the ith row and jth column.

3. A unique digit is a positive integer (without leading zeros) with no duplicate digits.
For example 7, 135 and 214 are all. Whereas 33, 3121 and 300 are not. Given two positive
integers, m and n, where m<n. Write a program to determine how many unique digit integers are
there in the range of m and n (both inclusive) and display them.

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

3. Write a program to determine if a string has all Unique Characters.[remove white space]
Given a string, determine if the string has all unique characters.
Day 4 (Classes and Objects)

1. Create a class called Time, which has three private 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 passes 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 display
( ) 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.

3. The annual examination results of N students are tabulated as follows:

Roll No. Subject 1 Subject 2 Subject 3


…..
…..

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


 Total marks obtain by each student
 The highest marks in each subject and the roll no of the student who secured it
 The student who obtained the highest total marks

4. Create a class called Time that has separate data member for hours, minutes and seconds. Define
member functions to perform the following tasks:
 to display the time in the format hh: mm: ss.
 to add times passed as arguments.
 to check which among two times passed as arguments is greater.
Write a program to test the class and its functions. Use constructor to initialize the instance
variables of the class Time.

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. Specify the instance variables and
methods for each class. The private 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 methods for getting and 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
getData and printData methods 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 an interface with at least one method, in its own package. Create a class in a separate
package. Add a protected inner class that implements the interface. In a third package, inherit
from your class and, inside a method, return an object of the protected inner class, up casting
to the interface during the return.

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 passes 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.

3. Write a program to create a class called Queue that includes functions to perform all operations
on a queue as well as raises an exception whenever overflow/underflow error occurs.

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. Each of the input, sort, and display methods is to
be synchronized.
3. Create two Thread subclasses, one with a run( ) that starts up, captures the reference of the
second Thread object and then calls wait( ). The other class’ run( ) should call notifyAll( ) for
the first thread after some number of seconds have passed, so the first thread can print a
message.

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 that inputs the names of people into different array list, A and B. Array A has
N number of names while array B has M number of names, with no duplicates in either of
them. Merge arrays A and B into a single array list C, such that the resulting array list is sorted
alphabetically. Display all the three arrays list, A, B and C, stored alphabetically. (Using Array
List)

3. Design the Generic Class Doubly Linked List that can contain any type of data. Implement the
all function.

4. Write a program that uses a StringTokenizer to tokenize a line of text input by the user and
places each token in a treeSet. Print the elements of the treeSet. [Note: This should cause
the elements to be printed in ascending sorted order.]

Day 11 (Graphics, AWT and Event Handling)

1. Write a program to calculate the future value of an investment amount and years. The formula
for the calculation is as follows:
futureValue = investment_amount x (1 + interest_rate)years
Use textfields for interest rate, investment amount and years. Display the future value in a text
field, when clicking the button.

2. Make the calculator using a Frame. The calculator should behave as a calculator, i.e. when
you hit the keys 3 + 2 = the screen should show 5, and so on.

You might also like