0% found this document useful (0 votes)
4 views

lab 4

Uploaded by

joyaluca2
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)
4 views

lab 4

Uploaded by

joyaluca2
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/ 2

Indian Institute of Information Technology, Allahabad

Object Oriented Methodology (OOM)


Lab-4 Assignment

Date of Lab: 28/08/2024 Instructors: Dr. Randheer Bagi

Note:
1) All Assignments should be done independently.
2) Try to develop Object Oriented Thinking for the problem given.
3) Write simple code in java for printing appropriate values.
4) Prepare a copy and write source code along with input and output for every
program given in the OOM lab/Tutorial wherever applicable.
5) Ready for a line-by-line explanation of your code running on your system.

Question 01:Write a Java program that demonstrates the use of interfaces. Create an interface
named 'Shape' with methods 'area()' and 'perimeter()' to calculate the area and perimeter of
different geometric shapes. Implement this interface in two classes: 'Circle' and 'Rectangle.' In
the 'Circle' class, take the radius as input, and in the 'Rectangle' class, take the length and width
as inputs. Calculate and display the area and perimeter of a circle and a rectangle using these
classes.

Question 02: Design a program in Java that simulates a basic banking system. Create an
interface named 'BankAccount' with methods 'deposit(double amount)' and 'withdraw(double
amount)' to manage account balances. Implement this interface in two classes: 'SavingsAccount'
and 'CheckingAccount.'
a. The 'SavingsAccount' class should have an additional method called 'calculateInterest()'
that calculates and adds interest to the account balance. Prompt the user to enter the
annual interest rate and initial balance when creating a 'SavingsAccount' object.
b. The 'CheckingAccount' class should have a method 'deductFees()' to deduct a monthly
fee from the account balance. Prompt the user to enter the fee amount and initial balance
when creating a 'CheckingAccount' object.
c. Create a main program that allows a user to create both a 'SavingsAccount' and a
'CheckingAccount,' and perform deposit, withdrawal, interest calculation, and fee
deduction operations based on user input.

Question 03: Imagine you are designing a system for a zoo. Create a Java program that
demonstrates the concept of abstraction. You should define an abstract class called Animal with
the following properties and methods:
● Properties:
● name (a string): to store the name of the animal.
● age (an integer): to store the age of the animal.
● Methods:
● abstract void speak(): This method should be abstract and is used to represent the
animal making a sound.
● void eat(): This method should display a message like "The animal is eating."

Now, create two concrete classes that extend the Animal class: Lion and Dolphin. Implement the
speak() method differently for each class. The Lion class should print "Roar!" when the speak()
method is called, and the Dolphin class should print "Ee-ee!".

In the main program, create instances of both Lion and Dolphin, set their names and ages, and
then call the speak() and eat() methods for each animal.

Ensure that you cannot create an instance of the Animal class directly (i.e., it should be abstract),
and each subclass provides its implementation of the speak() method.

You might also like