0% found this document useful (0 votes)
12 views4 pages

CSL37 OOP Question Bank 2021

The document is a question bank for the Object Oriented Programming Laboratory course for the III semester, detailing various programming tasks in Java. It includes assignments on inheritance, abstract classes, and method overriding, as well as practical applications involving classes like Vehicle, Shape, Student, and Car. Additionally, it covers multithreading, exception handling, and string manipulation tasks, with specific requirements for each programming exercise.

Uploaded by

sanskargondkar2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

CSL37 OOP Question Bank 2021

The document is a question bank for the Object Oriented Programming Laboratory course for the III semester, detailing various programming tasks in Java. It includes assignments on inheritance, abstract classes, and method overriding, as well as practical applications involving classes like Vehicle, Shape, Student, and Car. Additionally, it covers multithreading, exception handling, and string manipulation tasks, with specific requirements for each programming exercise.

Uploaded by

sanskargondkar2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Computer Science & Engineering

QUESTION BANK FOR III SEMESTER (Term: Aug-Dec 2021)

Object Oriented Programing Laboratory (CSL37)


I.A. Marks: 50 Exam Hours: 03
Credits: 0:0:1 Exam Marks: 50
Part-A

1. Write a Java Program that does the following related to Inheritance:


a. Create an abstract class called ‘Vehicle’ which contains the 'hashelmet',‘year of manufacture’ and two
abstract methods ‘getData()’ and ‘putData()’. Demonstrate the error when attempt is made to create objects
of ‘Vehicle’.
b. Have two derived classes ‘TwoWheeler’ and ‘FourWheeler’. ‘FourWheeler’ is a final class. Demonstrate
the error when attempt is made to inherit from ‘FourWheeler’.
c. Your abstract class should have overloaded constructors that initializes 'hashelmet' and ‘year of
manufacture for TwoWheeler and FourWheeler respectively.
d. ‘TwoWheeler’ has data elements ‘Brand’, ‘Cost’, ‘EngineType’ (possible values “2 stroke”, “4 stroke”), and
‘Color’ which are private, protected, ‘friendly/default’ and public respectively. Demonstrate the various
ways in which the two abstract methods can be dealt ‘getData()’ and ‘putData()’ can be dealt with by the
derived classes, ‘TwoWheeler’ and ‘FourWheeler’.

2. Write a Java Program that does the following:


a. Create an abstract class called ‘Shape’ which contains Two instance variables color (String)
and filled (boolean).
 Two constructors: a no-arg (no-argument) constructor that initializes the color to "green"
and filled to true, and a constructor that initializes the color and filled to the given values.
 Getter and setter for all the instance variables. By convention, the getter for
a boolean variable xxx is called isXXX() (instead of getXxx() for all the other types).
 A toString() method that returns "A Shape with color of xxx and filled/Not filled".
 An abstract method getArea()
 Demonstrate the error when attempt is made to create objects of ‘Shape’.
b. Write two subclasses of Shape called Circle and Rectangle. Rectangle is a final class. Demonstrate the error
when attempt is made to inherit from ‘Rectangle’.
c. Write a class called Square, as a subclass of Rectangle. Convince yourself that Square can be modeled as a
subclass of Rectangle. Square has no instance variable, but inherits the instance variables width and length
from its superclass Rectangle.

3. Write a Java Program that does the following


a. Create a superclass, Student, and two subclasses, Undergrad and Grad.
b. The superclass Student should have the following data members: name, ID, grade, age
c. The superclass, Student should have at least one method: Boolean isPassed (double grade)
d. The purpose of the isPassed method is to take one parameter, grade (value between 0 and 100) and
check whether the grade has passed the requirement for passing a course. In the Student class this
method should be empty as an abstract method.
e. The two subclasses, Grad and Undergrad, will inherit all data members of the Student class and
override the method isPassed. For the UnderGrad class, if the grade is above 70.0, then isPassed

HOD, Dept. of CSE


returns true, otherwise it returns false. For the Grad class, if the grade is above 80.0, then isPassed
returns true, otherwise returns false.
f. Demonstrate "final" keyword in the above class.
g. Create a test class for your three classes. In the test class, create one Grad object and one Undergrad
object. For each object, provide a grade and display the results of the isPassed method.

4. Write a Java Program that does the following


a. Create a super class called Car. The Car class has the following fields and methods.
 int speed; double regularPrice; String color; double getSalePrice();
b. Create a sub class of Car class and name it as Truck. The Truck class has the following fields and
methods.
 int weight; double getSalePrice();
 //Ifweight>2000,10% discount. Otherwise,20%discount.
c. Create a subclass of Car class and name it as Ford. The Ford class has the following fields and methods
 int year; intmanufacturerDiscount; double getSalePrice();
 //From the sale price computed from Carclass, subtract the manufacturer Discount.
d. Create a subclass of Car class and name it as Sedan. The Sedan class has the following fields and
methods.
 int length; double getSalePrice();
 //If length>20feet, 5% discount, Otherwise, 10% discount.
e. Create MyOwnAutoShop class which contains the main() method. Perform the following within the
main() method.
 Create an instance of Sedan class and initialize all the fields with appropriate values.
 Use super(...) method in the constructor for initializing the fields of the superclass.
 Create an instance of the Ford class and initialize all the fields with appropriate values
 Use super(...) method in the constructor for initializing the fields of the super class.
 Create an instance of Car class and initialize all the fields with appropriate values. Display the
sale prices of all instances.
5. Write a Java Program that implements the following
 Define a class SavingsAccount with following characteristics.
 Use a static variable annualInterestRate to store the annual interest rate for all account holders.
 Private data member savingsBalance indicating the amount the saver currently has on deposit.
 Method calculateMonthlyInterest to calculate the monthly interest as (savingsBalance *
annualInterestRate / 12). After calculation, the interest should be added to savingsBalance.
 Static method modifyInterestRate to set annualInterestRate.
 Parameterized constructor with savingsBalance as an argument to set the value of that instance.
 Test the class SavingsAccount to instantiate two savingsAccount objects, saver1 and saver2, with balances
of Rs.2000.00 and Rs3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly
interest and print the new balances for both savers. Then set the annualInterestRate to 5%, calculate the
next month’s interest and print the new balances for both savers.

HOD, Dept. of CSE


6. Write a Java Program that does the following
 The Customer class models a customer is design as shown in the class diagram. Write the codes for
the Customer class and a test driver to test all the public methods.

 The Invoice class, design as shown in the class diagram, composes a Customer instance (written
earlier) as its member. Write the codes for the Invoice class and a test driver to test all
the public methods.

7. We are required to model students and teachers in our application. We can define a superclass called Person to store
common properties such as name and address, and subclasses Student and Teacher for their specific properties. For
students, we need to maintain the courses taken and their respective grades; add a course with grade, print all courses
taken and the average grade. Assume that a student takes no more than 30 courses for the entire program. For
teachers, we need to maintain the courses taught currently, and able to add or remove a course taught. Assume that
a teacher teaches not more than 5 courses concurrently.

HOD, Dept. of CSE


PART-B
1. Write a program to create two threads t1, t2 which should prints odd numbers, and reverse of a number
respectively and stops thread after creating 3 odd numbers.
2. Design an Event handling Program to implement the following

3. Write a java program to throw a exception (checked) for an employee details• If an employee name is a
number, a name exception must be thrown. If an employee age is greater than 50, an age exception must be
thrown. Or else an object must be created for the entered employee details.
4. Write a Java program to find area of a triangle with three sides a, b, c. A triangle can be formed only if a+b>c,
b+c>a, c+a>b. First verify whether the above three conditions are satisfied. If any one of them is not satisfied
then throw an exception called ValidateTriangle Exception
Enter the 3 sides of triangle:
7 4 10
Valid Triangle
Enter the 3 sides of triangle:
268
Not a valid triangle
5. Write a Java program to display multiplication table of 8 & 9 using shared resources “synchronized
displayTable(intnum)”. The table should be displayed with 1 sec delay between every number. First print
multiplication table of 8 and then 9.
6. Write a Java program to implement "ADDTION" and "MULTIPLICATION" of two numbers using Lambda
Expressions
7. Write a java program to accept a string. Convert the string to uppercase. Count and output the number of
double letter sequences that exist in the string.
Sample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample Output: 4

Note:
Write up : 08 Marks
Conduction and Result : 35 Marks (a: 20 Marks, b: 15 Marks)
Viva : 07 Marks
For Change of question : 5+5 Marks

HOD, Dept. of CSE

You might also like