Question: write a program that can keep track of the composition of a train and its cargo. Your program will compute the length and speed of
write a program that can keep track of the composition of a train and its cargo. Your program will compute the length and speed of potential train configurations. You will need to write three classes to represent the train, the cars that carry the cargo and the locomotive that pulls the train.Class: LocomotiveA locomotive or engine is the vehicle that provides the pulling or pushing power for a train. The locomotive class should store information about the specifications of each engine: length, maximum payload, and maximum speed. The average length of a locomotive is meters. Length The length of the locomotiveengine in meters. Maximum Payload The maximum weight the locomotiveengine can pull in tons. Maximum Speed The maximum speed the train can travel with no cargo in miles per hour.Your locomotive class must implement methods to get the length, maximum payload, and maximum speed for all objects of the locomotive class: getlength Returns the length of the locomotiveengine in meters. getmaximumpayload Returns the maximum payload of the locomotiveengine in tons. getmaximumspeed Returns the maximum speed of the locomotive in miles per hour.Class: RailcarA railroad car or railcar is an unpowered vehicle used for carrying cargo or passengers. The railcar class should store information about the specifications of each railcar: length, type, minimum weight, maximum weight, and capacity. The average length of a rail car is meters. Length The length of the railcar in meters. Cargo Type The type of cargo being carried: Passenger o Freight Minimum Weight The weight of the railcar when at capacity in tons. Maximum Weight The maximum weight when at capacity in tons. Capacity The amount of cargo in the railcar as a fraction, of total capacity Max Weight Min WeightYour Railcar class must implement methods to get the length, cargo type, and current weight of a railcar object: getlength Returns the length of the railcar in meters. getcargotypel Returns the type of cargo. getweight returns the current weight of the railcar in tons.
Class: Train A train consists of at least locomotive and or more railcars. The train class should consist of two lists: locomotives and cars. The speed of the train is dependent on the maximum speed and the current payload of the railcars. The train's speed decreases linearly as its payload increases up to its maximum payload. The minimum speed of the train is of its maximum speed when at its maximum payload.The following attributes of the train class should be calculated from the list of locomotives and cars: Maximum Payload The maximum payload of the train is the sum of the maximum payload of its locomotives. Maximum Speed The maximum speed of the train is the maximum speed of the slowest locomotive pulling weight. Length The sum of the lengths of all locomotives and railcars. Payload The sum of the weight of all railcars. Speed The speed of the train given its current weight.Your Train class must implement methods to get the length, payload, and speed of the train in its current configuration: getlength Returns the length of the train in meters. getpayload Returns the weight of the cargo in tons. getspeed Returns the speed of the train in miles per hour.Your train class must implement methods to add and remove railcars and locomotives from the train: addrailcar railcar Adds the input railcar to the end of the train if the railcar does not cause the train to exceed its maximum payload. removerailcar Removes the railcar at the end of the train. addlocomotive locomotive Adds the input locomotive to the locomotive list. removelocomotive removes the last locomotive from the locomotive list if the locomotive is not the only locomotive in the train.You train class must implement a method to print out the composition of the train: printtrain Prints the following information about the planned train: Payload The weight of the cargo carried by all railcarsSpeed The speed of the train given the weight of its railcarsLength Length of the train including all railcars and locomotivesComposition Letter abbreviation for the locomotives and type of rail cars.
Example Output.Example OutputPayLoad: tonsSpeed: mphLength: meters L PPPPP FF FF F
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
