Question: AP Computer Scihy maximum weight,based on its power. The weight of all the train cars combined, including the engi must be below this maximum weight
AP Computer Scihy maximum weight,based on its power. The weight of all the train cars combined, including the engi must be below this maximum weight or the engine will not be able to move the train. The f complete Engine class is used to represent the train's engine. 2. A tain is compoacd of an engine and any number of train cars. The engine is rared to pull u Precondition: The maximum weight rating is greater than or equal to the weight of the sngine (every Rngine object can pull itself). Precondition: maximumieight is greater than or equal to the weight of the engine. public elass Sngine private double weight, maximumWeight publie Sngine (double vt, double maxwt) weight wt maximumWeight - maxWt public double getWeighto return weight ) public double getMaximumneight ) return maximumWeight: J retur Various train cars are represented by the Traincar class. The weight of a Traincar is its base weight plus of Traincar objects exist, including passenger cars, boxcars, flatcars, cabooses, and so on. Each of these types has a different way of calculating the weight of its contents. Since each type of Traincar does this differently, the getTotalkeight method is an abstract method. public abstract class TrainCar prvate double baseWeight public Traincar (double baseNt) baseWeight baset) public double getBaseWeight ) return baseWeight: public abstract double getTotalNeight )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
