Assignment 3 (1)
Assignment 3 (1)
CLO 2
1. Assume that the Account, BusinessAccount, and SavingAccount classes make up the inheritance
structure. The account information includes accountNo, yearOfOpening and balance. Depending
on the Account type an interest is to be applied. The interest rate on the BusinessAccount is
15%, while the interest rate on the SavingAccount is 10%. It is must for both these classes to
provide functionality for interest application.
You are required to design class diagram and implement the above scenario.
2. Prepare a program for a shop to maintain the records of its sold products by using following
concepts.
a. Product is an encapsulated class with attributes product name and its price. Include
method to return the bill of the product.
b. DiscountedProduct is also an encapsulated class that extends Product and it has an
attribute of discount. Include method to return the bill of discounted product.
c. Define a class named CustomerCart that represents a collection of multiple objects of type
Product or DiscountedProduct. The class will have an instance variable whose type is
Product[] , which will be used as a partially filled array. There will also be another instance
variable of type int that keeps track of how much of this array is currently used. Include
methods for the following:
• add a product in the cart. It can either be a product or discounted product
• display total bill
• display the number of products and discounted products in the cart individually
3. Consider a scenario where you are designing a software system for a zoo. The zoo has various
types of animals, such as mammals, birds, and reptiles. Each type of animal has common
attributes and behaviors, but also unique ones. Design a class hierarchy using abstract classes
and inheritance to represent this scenario.
a) Create an abstract class called Animal that has the following attributes:
i) A String variable named name to store the name of the animal.
ii) An integer variable named age to store the age of the animal.
An abstract method called eat() that represents the eating behavior of the animal.
A non-abstract method called sleep() that prints "The animal is sleeping."
b) Create two concrete classes, Mammal and Bird, that extend the Animal class. These classes
should define their own unique attributes and behaviors. For example, the Mammal class
could have an additional attribute furColor and a method run(), while the Bird class could
have an additional attribute wingSpan and a method fly().
Implement the eat() method in both the Mammal and Bird classes. The implementation
should print "The [animal name] is eating." where [animal name] is the name of the specific
animal.
Your task is to implement the classes according to the given requirements and demonstrate their
usage in a separate Main class.