Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN JAVA Develop the classes and interface represented in the following UML diagram: > Passenger * Train 1 String name String getName() void displayPassengers()

CODE IN JAVA

image text in transcribed

image text in transcribed

Develop the classes and interface represented in the following UML diagram: > Passenger * Train 1 String name String getName() void displayPassengers() has passengers String getName() String getFare Type() Person String firstName String lastName int age Passenger Includes the method signatures as per the diagram. Person The getName() returns a string of firstName and lastName separated by a space. The getFareType () method returns a string "Regular", "Youth" or "Senior" determined by a passenger's age : "Regular fare is the full fare, Youth is a reduced fare for children of age less than 18, and "Senior" is a reduced fare for people of age more than 65. Train The name field is the name of the train. Include another field for the required association. Add a method called displayPassengers () that prints the list of the names of those passengers, as given in the sample output below. Include other methods/fields/constructors as required but avoid adding any redundant methods/fields/constructors that are not being used anywhere in the program. Develop a TrainDriver class to test your code. You must add (hardcode) a few passengers to the train (all fare types must be illustrated, so you must add at least three). Display the train name using getName() method and passenger list using the displayPassengers () method on Train class. Sample output: Train name: Hogwarts Express Passengers: Youth Harry Potter Youth Hermione Granger Youth Ron Weasley Youth Ginny Weasley Regular Remus Lupin Senior Albus Dumbledore

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

Step: 3

blur-text-image

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions