Object Oriented Programing (CSE 2124)
Object Oriented Programing (CSE 2124)
A
Answer all the questions.
1A) Write a java program to enter the numbers till the user wants and at the end the program displays (4)
the largest, smallest, sum of the numbers, average of the numbers entered. Do-while loop should
be used to ask the user whether he or she wishes to perform the operation again. If so, the loop
should repeat; otherwise, it should terminate.
1B) Define two classes Car and Model class Car has a private variable carname and class Model has a (4)
private variable Modelname. Write zero argument and parameterized constructors to initialize the
data member and member functions to get, set and display the data member for these classes. In
the result class, write a merge() method which takes the 2 arguments as class Car and class Model
objects and concatenates the data members of these two objects. Write a main function that
creates instances of the classes Car and Model, assigns values to each and concatenates the value
of data member of these objects using the merge() method . Display the objects before and after
concatenation.
1C) Write a Java program to find duplicate values in an array of strings and display string and its (2)
number of occurrences.
2A) Write a Java program to create a class known as Person with members FirstName, LastName and (4)
methods called getFirstName() and getLastName(). Create a subclass called Employee with
members like empID and JobTitle, and a method named getEmployeeId() which overrides the
getLastName() method to include the employee's job title.
2B) Consider an Interface P with a data member p and a method disp(). Create two interfaces P1 and (3)
P2 which inherits interface P. Each interface P1 and P2 has a data member and one method.
Create a class Q which implements P1 and P2. Instantiate class Q and invoke each of its methods.
Each method displays one of the constants.
2C) Write a Java program to perform employee payroll processing using packages. In the java file, (3)
Emp.java creates a package employee and creates a class Emp. Declare the variables
name,empid, category, bpay, hra, da, npay, pf, grosspay, income tax, and allowance. Calculate the
values in methods. Create another java file Emppay.java. Create an object e to call the methods to
perform and print values.
3A) Write a Java program that intentionally generates ArithmeticException and (3)
ArrayIndexOutOfBoundsException. Implement suitable code to handle these exceptions.
Additionally, demonstrate when the "Unreachable catch block" error may arise and suggest how to
address it
3B) Elucidate the life cycle of Java threads, describe all the methods in it and depict the state transition (4)
diagram
3C) Create a Java program for a banking application featuring a BankAccount class and a custom (3)
exception called InsufficientFundsException. The BankAccount class should include attributes for
account number, account holder name, and current balance. Its withdraw method should throw
InsufficientFundsException if the withdrawal amount exceeds the current balance. In the main
Page 1 of 2
method of another class, showcase the usage of the BankAccount class by creating an account,
setting an initial balance, and attempting a withdrawal operation that could trigger the custom
exception
4A) Create a generic interface Stats with a method double avg() to compute and return the average of (4)
numeric values from the invoking object. Provide an implementation to this method through a class
StatsImpl, with appropriate data member(s). This class must also provide another member function
compareAvg() that compares the average of any two valid generic objects and returns true or false
appropriately. Demonstrate instantiation, computation, and comparison of average of generic
objects inside StatsDemo class by calling the above methods suitably.
4B) What are the two generic restrictions that apply to arrays? Explain the restrictions with the help of a (3)
program.
4C) How does CERT coding rule applies to division operations? Provide a suitable code showing both (3)
non-compliant and compliant versions.
5A) Write a Java Program to create a comboBox. The values for the comboBox are "Circle", (4)
"Rectangle", "Line". Based on the selection of the comboBox draw the shapes Circle, Rectangle or
Line on the window using Canvas
5B) Write a Javafx application such that a user creates three text fields and enters "length", "breadth" (4)
and "color", where color can take values of red, green and blue. Create a push button with name
"Render" on it. On clicking "Render" button, the application should render rectangle of the entered
length, breadth and color using canvas. User GridPane layout.
5C) Write and justify the output for the following Java program. (2)
-----End-----
Page 2 of 2