Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Explanation / Answer

class computer { protected string name; protected double downloadspeed; public computer(string compname,double speed) { name = compname; downloadspeed = speed; } } class personnelcomputer extends computer { protected double connectiontime; public personnelcomputer(string name,double speed,double time) { super(name,speed); connectiontime = time; } protected double totalMegaBytesDownloaded() { return double tmbd = connectiontime * super.downloadspeed; } } class desktop extends personnelcomputer { protected bool goodcondition; public desktop(string name,double speed,double time,bool condition) { super(name,speed,time); goodcondition = condition; } //here totalMegaBytesDownloaded is a polymorphic method as it is using same //method name, but with different method parameters protected double totalMegaBytesDownloaded(bool isgoodcondition) { double tmbd = connectiontime * super.downloadspeed; if(isgoodcondition) { tmbd += tmbd*0.2; } else { tmbd -= tmbd*0.2; } return tmbd; } } class laptop extends personnelcomputer { protected bool wirelessavailable; public laptop(string name,double speed,double time,bool condition,bool wireless) { wirelessavailable = wireless; super(name,speed,time,condition); } //here totalMegaBytesDownloaded is a polymorphic method as it is using same //method name, but with different method parameters, here two parameters are used protected double totalMegaBytesDownloaded(bool isgoodcondition,bool wireless) { double tmbd; if(wireless) { tmbd = 3000; } else { tmbd =0; } return tmbd; } } public class program { public static void main() { computer[] comps = new computer[6]; computer c1 = new laptop(“Toshiba”, 56.5, 100, true); computer c2 = new laptop(“HP”, 60, 90, true); computer c3 = new laptop(“Dell”, 70, 110, true); computer c4 = new desktop(“lenovo”, 50.0, 80, true); computer c5 = new desktop(“Compaq”, 60.0, 70, true); computer c6 = new desktop(“Acer”, 80.0, 90, true); comps[0] =c1; comps[1] = c2; comps[2] = c3; comps[3] = c4; comps[4] = c5; comps[5] = c6; int noofdesktops,nooflaptops; double tmddesktop,tmblaptop; double avgdesktop;avglaptop; int noofdesktopsingoodcondition=0; int nooflaptopswirelessnotavailable=0; for(int count =0; count
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote