Birla Institute of Technology & Science, Pilani
Work-Integrated Learning Programmes Division
HCL BSc (Design & Computing) Cohort-X Semester-Y
Course Title : OBJECT ORIENTED PROGRAMMING DESIGN
Nature of Exam : Open Book
Weightage : 40%
Duration : 3 Hours
Date of Exam :
Note:
1. Please follow all the Instructions to Candidates given on the cover page of the answer book.
2. All parts of a question should be answered consecutively. Each answer should start from a fresh page.
3. Assumptions made if any, should be stated clearly at the beginning of your answer.
Answer ALL the questions
All Questions carry equal marks (5 x 8 = 40 marks)
Question 1 Set (A) (8 marks)
Write a Java program to create a class Product with product name, product id, rate,
and type as attributes with required constructor and a display method to display
product details. Create a class Pen that extends Product and has attribute brand.
Define the required constructor to initialize the data. Create a class Book that extends
Product with attribute title and define the constructor to initialize the data. In the main
class, create objects for Pen and Book and display the all the details of the created
products.
Question 2 Set (A) (8 marks)
Write a Java program that creates a user defined exception WrongEmailID with
required constructors. Create a class User with attribute user name, password, and
email id. Define a method userRegistration() that takes the user details and throws
WrongEmailID exception if the “@” and “.” characters are missing in the entered
email id. In the main class create required instances and call userRegistration()
method with required code to handle wrong inputs.
Question 3 Set (A) (8 marks)
Write a java program to create a HashMap that stores names of students. Add the
names of your friends in the HashMap. Use appropriate classes and methods to sort
the elements in the HashMap and print the sorted Map.
Question 4 Set (A) (8 marks)
Write a Java program to create a class Numbers which has a method checkNumber
which takes an integer as input and checks if the number is prime or not and prints a
message “It’s a prime number” or “It’s not a prime number” accordingly. Create two
classes PrimeNumber and NonPrimeNumber both of which extends Thread and has
an object of type Number and implements the run method and calls he checkNumber()
method using the Number object. Define appropriate constructors for the defined
classes. Create the main class, create objects for the Number, PrimeNumber and
NonPrimeNumber classes and start the threads. Write the expected output of your
program for a given input.
Question 5 Set (A) (8 marks)
Write a Java program to create a class Student with name, id and gpa with required
constructors and a display method to display the student details. In the main class
create 5 instances of Student. Create an ArrayList stuList and add the 5 students. Use
the get() method of ArrayList to get the data from the stuList and check if they are
instances of the Student class. If they are instances of Student class then print their
details by calling the display() method.