Question: Assignment 4 - Train, PassengerTrain and CargoTrain Classes Design a Train class with the following members: A field for the name of the train A
Assignment 4 - Train, PassengerTrain and CargoTrain Classes Design a Train class with the following members:
A field for the name of the train
A field for the year that the train was built
A constructor and appropriate setters (accessors) and getters (mutators)
A toString method that displays the trains name and year it was built
Design a Passenger Train class that extends the Train class. The Passenger Train class should have the following members:
A field for the maximum number of passengers
A constructor and appropriate setters and getters
A toString method that overrides the toString method in the base class. The Passenger Train classs toString method should display the trains name and the maximum number of passengers.
Design a Cargo Train class that extends the Train class. The Cargo Train class should have the following members:
A field for the cargo capacity in tonnage
A constructor and appropriate setters and getters
A toString method that overrides the toString method in the base class. The Cargo train classs toString method should display on the Trains name and the trains cargo capacity.
Demonstrate the classes in a program that has a Train array. Assign various Train, Passenger Train and Cargo Train objects to the array elements. The program should then step through the array, calling each objects toString method.
Include a UML class diagram depicting the relationship between the three classes (include fields and methods in diagram)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
