Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****IN JAVA**** You are to write a Train class which performs certain operations on the train. These operations will be given in a text file

****IN JAVA****

You are to write a Train class which performs certain operations on the train. These operations will be given in a text file that must be read in main method.

A train pulls boxcars, which contain things like cargo and people, from one destination to another. A train can pull many boxcars containing "things" of different types at the same time. For example, a train may pull five boxcars of people and ten boxcars of cargo, with the boxcars in any order. Note, however, that an individual boxcar will contain only one type of "thing" at any given time (for example, all people or all cargo).

A train has some basic behaviors no matter how many and what type of boxcars it is pulling, such as departing a station, arriving at a station, loading, unloading, adding boxcars, and removing boxcars. Because all boxcars have the same behaviors, it is appropriate to design and implement a generic boxcar class.

Design and implement a generic class to model a box car

Design and implement a class to model cargo

Design and implement a class to model a person

Design and implement a class to model a train that can simulatenously pull both cargo and person boxcars

Write a constructor for Train that takes in

The train's city of origin

The train's minimum allowable speed

The train's maximum allowable speed

The maximum number of box cars the train can pull

Handle all possible errors gracefully, either through Exceptions or another strategy

The operations that the the train is to perform will be read from a text file, the name of which will always be "train_commands.txt". The formats of the PRINT, ARRIVE, DEPART, SPEEDUP, SLOWDOWN, ADDCAR, REMOVECAR, LOAD, UNLOAD, and QUIT commands are described below. City names, person names, and unique cargo labels may be multi-word strings. Commands and unique government-issued IDs do not contain spaces.

THE COMMAND FILE

PRINT - prints the following information to the screen

The Train's Current Speed

The Train's Maximum Speed

The Train's Minimum Speed

The Train's current position (e.g. "Traveling from Washington to Baltimore")

The current number of boxcars the train is pulling

The maximum number of boxcars the train can pull

Details of each boxcar being pulled. For each boxcar you should print:

The unique boxcar ID (It's index e.g. the first box car has ID 0, the second one has ID 1, and so on)

The details of each "thing" being transported, or a message that the boxcar is empty

ARRIVE - The train reaches its destination, is parked, and ready for loading, unloading, adding boxcars, and removing boxcars

DEPART - The train moves at its minimum speed towards the new destination

SPEEDUP - The train increases its speed by the specified number of miles per hour

SLOWDOWN - The train decreases its speed by the specified number of miles per hour

ADDCAR - The train gets a new boxcar added to the end. The only valid types are CARGO and PERSON. The maximum number of elements is unrelated to any attributes. For example, one piece of cargo is simply one piece, regardless of its size.

REMOVE < boxcar ID > - Removes a boxcar from the train. If a boxcar is removed from the middle of the train, all the boxcars behind it should be reassigned a new ID based on their new position in the train

QUIT - Indicates the end of the command file

The format for LOAD and UNLOAD are different for each "thing" a boxcar is carrying.

LOAD (CARGO|PERSON)A Boxcar carying cargo: LOAD CARGO

The boxcar ID is a valid integer, cargo ID is a string, and height and weight are positive integers. The units are irrelevant.

A Boxcar carying people: LOAD PERSON

The boxcar ID is a valid integer, the government ID and name are strings, and the age in a positive integer.

UNLOAD

A boxcar carrying cargo: UNLOAD

boxcar ID is an integer, cargo ID is a string

A boxcar carrying people: UNLOAD

boxcar ID is an integer, government ID is a string

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions