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/ 5
Green University of Bangladesh
Department of Computer Science and Engineering (CSE)
Faculty of Sciences and Engineering Semester: (Fall, Year:2024), B.Sc. in CSE (Day)
Lab Report NO # 5&6
Course Title: Object Oriented Programming
Course Code: CSE 201 Section: D9
Lab Experiment Name: Implementation of Interface and Multiple Inheritance and
Exception, Custom Exception, and use of Exception Handling keywords
Student Details
Name ID Jannatul Bushra 232002255
Lab Date :11/11/2024
Submission Date : 24/11/2024 Course Teacher’s Name : Wahia Tasnim
Lab Report Status
Marks: ………………………………… Signature:..................... Comments:.............................................. Date:.............................. 1. Create an interface isEmergency with only one method - soundSiren which takes no arguments and returns no value. • Write a class FireEmergency that implements the IsEmergency interface. The soundSiren method shouldprint "Siren Sounded". • Write a class SmokeAlarm that does not implement any interface. The class has an empty body. • Create an array of Object class, myArray in the main method. • Construct 2 SmokeAlarm object and add it to the array myArray in the main method. • Construct 2 FireEmergency object and add it to the array myArray in the main method. • In the main method, write a for loop, to print which array elements are instances of classes that implement the IsEmergency interface and if so, call the soundSiren method. Output :
2. Create an exception class named AgeOutOfRangeException extended from
the class Exception. This class should contain a constructor which takes the user’s age (ex. 40) as parameter. Will print following message when called, "You are older than the requested age (25 years), you are 40!!!”. Create an exception class named LowGpaException extended from the class Exception. This class should contain a constructor, with no parameter. The constructor will call the Exception class constructor with the message "Your GPA is not sufficient to apply for this job (2.5)". Create a main class named GPA to prompt the user to enter his/her age and his GPA. The user application for a job will be rejected either if his age is greater than 25 years or his GPA is less than 2.5. You should declare two try- throw-catch blocks; one to handle the AgeOutOfRangeException and the other to handle the LowGpaException. If the user enters acceptable age and GPA, display the message "Your application is accepted and is under study". Output :