Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

What sequencing rules do you think the tower controllers use?

Answered: 1 week ago