Question: Q 1 : About Polymorphism 5 P t s Consider the following inheritance hierarchy. A class 'Computer' that has: One instance variable name of type
Q: About Polymorphism
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 MBsmegabytessecond
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:
if goodCondition true, the total MB downloaded are increased by
if goodCondition false, the total MB downloaded are reduced by
A Laptop class which is a subclass of PersonalComputer that:
as an additional variable "wirelessAvalable" of type boolean.
overrides totalMegaBytesDownloaded method as follows:
if wirelessAvailable true, the total MB downloaded is
if wirelessAvailable false, the total MB downloaded is zero.
Page of
Provide suitable constructors accessormutator methods and a tostring method for
all the classes. Write an application class that generates an array of type Computer of
objects from either a Desktop or a Laptop. For example
Computer e new LapTop Toshiba 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
