Homework 6
Homework 6
Topics :
LAB Exercises :
Give the Java code for constructing an object of class Rectangle, and for declaring an
object variable of class Rectangle and do the following :-
• A rectangle with center (100, 100) and all side lengths equal to 50 Use the
getWidth( ) and getHeight( ) methods. Specify Accessor and Mutator methods.
Design and implement and test your Rectangle class with ( x , y , width , height ) as
attributes and apply constructors and ( setters & getters ) for the previous attributes
?
Design and implement and test a class that models a tally counter, a mechanical
device that is used to count people—for example, to find out how many people attend
a concert or board a bus .
Design and implement and test BankAccount class that has the following attributes :
accountID , accountholder , and amount after that create constructor and the
following methods :
• deposit ( double amount )
• withdraw ( double amount )
• setters for accountID and accountholder.
• getters for all attributes.
Design and implement Student class that has the following attributes : id , name , age
and major after create that create constructor and ( setters & getters ) for the previous
attributes. Create multiple constructors for the Student class . ( apply overloading )
Explain constructor chaining.
Design and Implement and test a Product class with fields for id , name, price, and
quantity. Implement multiple constructors that initializes these fields and ( setters &
getters ) for the product attributes finally create a methods the first one called
discount( int percentage ) and the second one called displyDetails() to print the details
of the product and discount.
Design and implement and test a class called Date, which models a calendar date ,
date, is designed as shown in the following class diagram :
+ displayTime( )
: void
HW :
Design and implement and test a class Book . A book has a title , authorName and price .
apply constructors and methods ( setter and getter ) , after that test your class in Main class
and create three Book objects and print their details . ( apply Encapsulation to this class ) .
Design and implement and test a class that models a self-service cash register. The customer
scans the price tags and deposits money in the machine. The machine dispenses the change.
( apply Encapsulation to this class ) .
From the following class diagram implement and test Circle class :