Question: WRITE THE CODE IN JAVA public class HeavyTruck { public String name; public int numberof Tyres; public int load Amount; private int maxLoad; public Truck(string


WRITE THE CODE IN JAVA
public class HeavyTruck { public String name; public int numberof Tyres; 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. It should throw illegal //argument exception with a message if load amount is greated than new Load. // bu yntem, verilen newload'a gre loadAmount'u artrmaldr. Ykleme miktar newLoad'dan bykse, bir mesajla geersiz argman istisnas atmaldr. } } public class Garbage Truck { public String name; public int numberof Tyres; public int load Amount; private int max Load; public Truck(String name, int not, int maxLoad) { this.name = name; this.numbero ftyres Enot; this.max Load = 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 maxLoad; public Truck(String name, int not, int maxLoad) { this.name = name; this.numbero ftyres Enot; 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. This is a problem. We don't want this. 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 another method to print all loads. c) In main method, create a Factory object and let it compute all loads and print them
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
