Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Assignment #1

1) Create a class called Person with attributes such as name, age, and address.Make 2shapes of
Constructors of your choice and implement the setters and getters to all attributtes.In main,
create an instance of the class and print out the attributes using toString method.
2) A class called Account, which models a bank account of a customer, is designed as shown in
the following class diagram. The methods credit(amount) and debit(amount) add or
subtract the given amount to the balance. The method transferTo(anotherAccount,
amount) transfers the given amount from this Account to the given anotherAccount. Write
the Account class.
3) In this question, a subclass called Cylinder is derived from the superclass Circle as shown
in the class diagram (where an an arrow pointing up from the subclass to its superclass).
Study how the subclass Cylinder invokes the superclass' constructors
(via super() and super(radius)) and inherits the variables and methods from the
superclass Circle.
The method : getVolume() is a public method for computing the volume of cylinder use superclass
method getArea() to get the base area.
4) Create a Counter class with a static variable count and two methods, increment and decrement,
which increment and decrement the count variable respectively. Also, create a method
getCount which returns the current value of count. Test your Counter class by creating multiple
objects and invoking the methods on them and print the value of the counter after methods
invoking.
5) Create an Animal class with attributes such as name, age, species, and color. Add methods such
as makeSound and eat that allow users to interact with an Animal object. (just print a statement
inside)

6) Create a Dog class that extends the Animal class. Add additional attributes such as breed and
ownerName. Override the makeSound method to make a dog-specific sound.
7) Create a Cat class that extends the Animal class. Add additional attributes such as breed and
ownerName. Override the makeSound method to make a cat-specific sound.

8) Create a Bird class that extends the Animal class. Add additional attributes such as wingSpan and
flightSpeed. Override the makeSound method to make a bird-specific sound.
9) Create a Fish class that extends the Animal class. Add additional attributes such as waterType
and swimSpeed. Override the makeSound method to make a fish-specific sound.

10) Create a Zoo class that contains an array of Animal objects with different species . Add methods
such as addAnimal and removeAnimal that allow users to add or remove an Animal object from
the list, and finding animals based on their name, age, or gender that return a Boolean search
result .

11) Implement the main for the tasks from 4 to 9 with making instances and called methods and use
these instances in task 10.
Good Luck

Alaa Elkholi

You might also like