Question: JAVA public cla55 HeavyTruck { public String name; public int numberofTyres; public int load Amount; private int maxLoad; public Truck(String name, int not, int maxLoad)

 JAVA public cla55 HeavyTruck { public String name; public int numberofTyres;

public int load Amount; private int maxLoad; public Truck(String name, int not,

int maxLoad) { this.name = name; this.numberOfTyres =not; this.max Load = maxLoad;

} void load(int newLoad) { // this method must increment loadAmount with

JAVA

public cla55 HeavyTruck { public String name; public int numberofTyres; public int load Amount; private int maxLoad; public Truck(String name, int not, int maxLoad) { this.name = name; this.numberOfTyres =not; this.max Load = maxLoad; } void load(int newLoad) { // this method must increment loadAmount with respect to given newload. //argument exception with a message if load amount is greated than new Loa 1/ bu yntem, verilen newload'a gre loadAmount'u artrmaldr. Ykleme bir mesajla geersiz argman istisnas atmaldr. } } public class Garbage Truck { public String name; public int numberOfTyres; public int load Amount; private int maxLoad; public Truck(String name, int not, int maxLoad) { this.name = name; this.numberofTyres Enot; this.max Load h maxLoad; } void load(int newLoad) { // same as the other load method public class Tanker Truck { public int numberOf Tyres; public String name; public int load Amount; private int max Load; public Truck(String name, int not, int maxLoad) { this name name. this. HaxLoad = maxLoad; } void load(int newLoad) { 11 this method must increment loadAmount with respect to given neule I/argument exception with a message if load amount is greated than ne 1/ bu yntem, verilen newLoad'a gre loadAmount'u artrmaldr. Ykle bir mesajla geersiz argman istisnas atmaldr. } public class GarbageTruck public String name; public int numberOfTyres; public int load Amount; private int maxLoad; public Truck(String name, int not, int maxLoad) { this.name = name; this.numberofTyres =not; this.maxLoad = maxLoad; } void load(int newLoad){ // same as the other load method) } public class Tanker Truck { public int numberof Tyres; public String name; public int load Amount; private int max Load; public Truck(string name, int not, int maxLoad) { this.name = name; this.numberoftyres =not; this.max Load = maxLoad; void load(int newload) { // same as the other load method}} Question: There are 3 classes on the right where many codes have been repeated, void load(int newLoad) { //same as the other load method}} Question: There are 3 classes on the right where many codes have been repeated. This is a problem. We don't So, a) Using OOP inheritance and polymorphism principles, rewrites the codes to reuse existing codes. b) Create a class called Factory where there will be an array of trucks. Constructor must take the array as parameters. Write a method in Factory class to compute all loads of the trucks in the Factory. Write an method to print all loads. c) In main method, create a Factory object and let it compute all loads and print them. Soru Verilen Classlarda ok fazla kod tekrar var. Bu bir sorundur. Gelitirici olarak bu istemediimiz bir eydir. a) OOP miras ve polimorpfhism ilkelerini kullanarak, mevcut kodlar tekrar tekrar kullanabilen kodlar yeni yaznz. b) Bir Truck dizisi ieren Factory adl bir sinif oluturun. Yapc (constructor), diziyi parametre olarak almalie Factorydeki trucklarin tm yklerini hesaplamak iin Factory snfnda bir yntem yazn. Tm ykleri yaz baka bir yntem yazn. main method da, bir Factory nesnesi oluturun ve tm Factorydeki ykleri hesaplatn ve yazdrn. 7 . B I = E EE tion: There are 3 classes on the right where many codes have been repeated. This is a problem. We don't want this. ) Using OOP inheritance and polymorphism principles, rewrites the codes to reuse existing codes. Create a class called Factory where there will be an array of trucks. Constructor must take the array as parameters. Write a method in Factory class to compute all loads of the trucks in the Factory. Write another method to print all loads. ) In main method, create a Factory object and let it compute all loads and print them. Verilen Classlarda ok fazla kod tekrar var. Bu bir sorundur. Gelitirici olarak bu istemediimiz bir eydir. OOP miras ve polimorpfhism ilkelerini kullanarak, mevcut kodlar tekrar tekrar kullanabilen kodlar yeniden yaznz. ) Bir Truck dizisi ieren Factory adl bir sinif oluturun. Yapc (constructor), diziyi parametre olarak almaldr. Factorydeki trucklarin tm yklerini hesaplamak iin Factory sinfnda bir yntem yazn. Tm ykleri yazdrmak iin baka bir yntem yazn. main method da, bir Factory nesnesi oluturun ve tm Factorydeki ykleri hesaplatin ve yazdrn. A B

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!