This is a Java program I hope you comment on polymorphisim lines and explain why
ID: 3629818 • Letter: T
Question
This is a Java program I hope you comment on polymorphisim lines and explain why you did it.
Polymorphisim is really hard and I couldn't do it.
I know it deserve more then a 350+ point but points fixed here :S
Consider the following inheritance hierarchy.
A class ‘Computer’ that has:
- One instance variable “name” of type String.
- One instance variable “downloadSpeed” of type double giving download speed of the network in MB/s. (megabytes/second)
A subclass ‘PersonalComputer’ that:
- has one additional private instance variable “connectionTime” of type double indicating the number of seconds the computer was connected.
- one method “totalMegaBytesDownloaded()” calculating the Total megabytes downloaded by mutiplying the downloadSpeed by connectionTime.
A Desktop class which is a subclass of PersonalComputer that :
- has an additional variable “goodCondition” of type boolean.
- overrides totalMegaBytesDownloaded() method as follows:
o if goodCondition = true, the total MB downloaded are increased by 20%
o if goodCondition = false, the total MB downloaded are reduced by 20%
A Laptop class which is a subclass of PersonalComputer that:
- as an additional variable “wirelessAvailable” of type boolean.
- overrides totalMegaBytesDownloaded() method as follows:
o if wirelessAvailable = true, the total MB downloaded is 3000 MB.
o if wirelessAvailable = false, the total MB downloaded is zero.
Provide suitable constructor(s), accessor/mutator methods and a toString() method for all the classes. Write an application class that generates an array of type Computer of 6 objects from either a Desktop or a Laptop. For example
Computer c1 = new LapTop(“Toshiba”, 56.5, 100, true);
Print the following information about your array:
• the total number of desktops in your collection
• the total number of laptops in your collection
• the total MB downloaded by all desktops in your collection
• the total MB downloaded by all laptops in your collection.
• the average MB downloaded by all desktops in your collection.
• the average MB downloaded by all laptops in your collection.
• the number of desktops in good condition.
• the number of laptops with wireless not available.