You are on page 1of 1

HAS-A-Relationship assignment

Create a class Computer with instance variable companyname, price, monitor and
keyboard .Data type of monitor is Monitor class which has its own instance variable size ,
type and brandName. Datatype of keyboard is KeyBoard class with its own instance
variable type,noofkeys. Create separate classes Monitor and KeyBoard and using
parameterized constructor assign the values in instance variables. Using getDetails method
in each class fetch all the relevant information. Create setData method in Computer class
and using object passing concept initialize all the values in instance variables.
Using getData method print the details of Computer as a whole along with Monitor and
KeyBoard details.
Create object of Computer in main method of ComputerDemo class and call all the
relevant methods to implement the concept of HAS-A-Relationship
Note:
 Do not create bean classes make it as normal class as we did in Book and
Student
 setData() signature will be like this->
Void setData(String companyname,float price,Monitor monitor,KeyBoard keyboard)

You might also like