home / study / engineering / computer science / computer science questions and a
ID: 3753908 • Letter: H
Question
home / study / engineering / computer science / computer science questions and answers / java please... in this assignment, you will write a train car manager for a commerical train. ...
Question: Java please... In this assignment, you will write a train car manager for a commerical train. The...
Edit question
Java please...
In this assignment, you will write a train car manager for a commerical train. The train, modelled using a Double-Linked List data structure, consists of a chain of train cars, each of which contains a product load. A product load has a weight, a value, and can be dangerous or safe. The train car manager will be able to add and remove cars from the train, set the product load for each car, and determine useful properties of the train, such as it's length, weight, total value, and whether it contains any dangerous product loads.
1. Write a fully-documented class named ProductLoad which contains the product name (String), it's weight in tons (double), it's value in dollars (double), and whether the product is dangerous or not (boolean). You should provide accessor and mutator methods for each variable. The mutator methods for weight and value should throw exceptions for illegal arguments (i.e. negative values). The class should include a constructor. The full list of required methods is:
public ProductLoad - constructor (you may include a constructor with parameters)
getter and setter methods for each variable
2. Write a fully-documented class named TrainCar which contains a length in meters (double), a weight in tons (double), and a load reference (ProductLoad). The load variable of the train may be null, which indicates that the train car is empty and contains no product. The train car should have accessor methods for the length, weight, and load variables; however, you should only provide a mutator method for the load variable (the car weight and length should be constant once set). In addition, the class should specify a constructor method (with whatever parameters are necessary), and a method determining whether the car is empty or not. The full list of required methods is:
public TrainCar - constructor (you may include a constructor with parameters)
getter methods for each variable
setter method only for the load variable.
isEmpty() method
3.
Write a fully-documented class named TrainCarNode which acts as a node wrapper around a TrainCar object. The class should contain two TrainCarNode references (one for the next node in the chain, one for the previous node in the chain), and one TrainCar reference variable containing the data. Include mutator/accessor methods for each member variable, and a constructor method. The full list of required methods is:
public TrainCarNode - constructor (you may include a constructor with parameters)
getter and setter methods for each variable
4. Write a fully-documented class named TrainlinkedList which implements a Double-Linked List ADT. The class should contain references to the head and tail of the list, as well as a cursor variable (all TrainCarNode), and should provide methods to perform insertion, deletion, search, and various other operations. The class will be based on the following ADT specification:
public class TrainLinkedList
The TrainlinkedList class implements an abstract data type for a Double-Linked List of train cars supporting some common operations on such lists, as well as a few others.
public TrainLinkedList()
Brief:
Constructs an instance of the TrainLinkedList with no TrainCar objects in it.
Postconditions:
This TrainLinkedList has been initialized to an empty linked list.
head, tail, and cursor are all set to null.
public TrainCar getCursorData()
Brief:
Returns a reference to the TrainCar at the node currently referenced by the cursor.
Preconditions:
The list is not empty (cursor is not null).
Returns:
The reference to the TrainCar at the node currently referenced by the cursor.
public void setCursorData(TrainCar car)
Brief:
Places car in the node currently referenced by the cursor.
Preconditions:
The list is not empty (cursor is not null).
Postconditions:
The cursor node now contains a reference to car as its data.
public void cursorForward()
Brief:
Moves the cursor to point at the next TrainCarNode.
Preconditions:
The list is not empty (cursor is not null) and cursor does not currently reference the tail of the list.
Postconditions:
The cursor has been advanced to the next TrainCarNode, or has remained at the tail of the list.
public void cursorBackward()
Brief:
Moves the cursor to point at the previous TrainCarNode.
Preconditions:
The list is not empty (cursor is not null) and the cursor does not currently reference the head of the list.
Postconditions:
The cursor has been moved back to the previous TrainCarNode, or has remained at the head of the list.
public void insertAfterCursor(TrainCar newCar)
Brief:
Inserts a car into the train after the cursor position.
Parameters:
newCar - the new TrainCar to be inserted into the train.
Preconditions:
This TrainCar object has been instantiated
Postconditions:
The new TrainCar has been inserted into the train after the position of the cursor.
All TrainCar objects previously on the train are still on the train, and thier order has been preserved.
The cursor now points to the inserted car.
Throws:
IllegalArgumentException - Indicates that newCar is null.
public TrainCar removeCursor()
Brief:
Removes the TrainCarNode referenced by the cursor and returns the TrainCar contained within the node.
Preconditions:
The cursor is not null.
Postconditions:
The TrainCarNode referenced by the cursor has been removed from the train.
The cursor now references the next node, or the previous node if no next node exists.
public int size()
Brief:
Determines the number of TrainCar objects currently on the train.
Returns:
The number of TrainCar objects on this train.
Notes:
This function should complete in O(1) time.
public double getLength()
Brief:
Returns the total length of the train in meters.
Returns:
The sum of the lengths of each TrainCar in the train.
Notes:
This function should complete in O(1) time.
public double getValue()
Brief:
Returns the total value of product carried by the train.
Returns:
The sum of the values of each TrainCar in the train.
Notes:
This function should complete in O(1) time.
public double getWeight()
Brief:
Returns the total weight in tons of the train. Note that the weight of the train is the sum of the weights of each empty TrainCar, plus the weight of the ProductLoad carried by that car.
Returns:
The sum of the weight of each TrainCar plus the sum of the ProductLoad carried by that car.
Notes:
This function should complete in O(1) time.
public boolean isDangerous()
Brief:
Whether or not there is a dangerous product on one of the TrainCar objects on the train.
Returns:
Returns true if the train contains at least one TrainCar carrying a dangerous ProductLoad, false otherwise.
Notes:
This function should complete in O(1) time.
public void findProduct(String name)
Brief:
Searches the list for all ProductLoad objects with the indicated name and sums together their weight and value (Also keeps track of whether the product is dangerous or not), then prints a single ProductLoad record to the console.
Parameters:
name - the name of the ProductLoad to find on the train.
Notes:
This method should search the entire train for the indicated ProductLoad, and should not stop after the first match. For example, if there are three different TrainCar objects each carrying a ProductLoad with the name "corn", then this method should print a single record with the sum of the weight and value for the corn on each car. If nothing was found, indicate that there are no ProductLoadobjects of the indicated name on board the train.
For the purposes of this assignment, you may assume that the dangerousness of loads with equal names are equal. Simply use the boolean value of isDangerous for the first match found.
public void printManifest()
Brief:
Prints a neatly formatted table of the car number, car length, car weight, load name, load weight, load value, and load dangerousness for all of the car on the train.
Notes:
There should be a record for each TrainCar printed to the console, numbered from 1 to n. For each car, print the data of the car, followed by the ProductLoad data if the car is not empty. If the car is empty, print "Empty" for name, 0 for weight and value, and "NO" for dangerousness (see sample I/O for example).
public void removeDangerousCars()
Brief:
Removes all dangerous cars from the train, maintaining the order of the cars in the train.
Postconditions:
All dangerous cars have been removed from this train.
The order of all non-dangerous cars must be maintained upon the completion of this method.
Notes:
All the dangerous cars may be discarded after calling this method.
public String toString()
Brief:
Returns a neatly formatted String representation of the train.
Returns:
A neatly formatted string containing information about the train, including it's size (number of cars), length in meters, weight in tons, value in dollars, and whether it is dangerous or not.
5. Write a fully-documented class named TrainManager that is based on the following specification:
public class TrainManager
public static void main(String[] args)
The main method runs a menu driven application which first creates an empty TrainLinkedList object. The program prompts the user for a command to execute an operation. Once a command has been chosen, the program may ask the user for additional information if necessary, and performs the operation. The operations should be defined as follows:
F - Move Cursor Forward
Moves the cursor forward one car (if a next car exists).
B - Move Cursor Backward
Moves the cursor backward one car (if a previous car exists).
I - Insert Car After Cursor
Inserts a new empty car after the cursor. If the cursor is null (i.e. the train is empty), the car is set as the head of the train. After insertion, the cursor is set to the newly inserted car.
R - Remove Car At Cursor
Removes the car at current position of the cursor. After deletion, the cursor is set to the next car in the list if one exists, otherwise the previous car. If there is no previous car, the list is empty and the cursor is set to null.
L - Set Load At Cursor
Sets the product load at the current position in the list.
S - Search For Product
Searches the train for all the loads with the indicated name and prints out the total weight and value, and whether the load is dangerous or not. If the product could not be found, indicate to the user that the train does not contain the indicated product.
T - Print Train
Prints the String value of the train to the console.
M - Print Manifest
Prints the train manifest - the loads carried by each car.
D - Remove Dangerous Cars
Removes all the dangerous cars from the train.
Q - Quit
Terminates the program.
Note: You may include additional member variales or methods in any class as necessary or as you find convenient.
INPUT FORMAT:
Each menu operation is entered on its own line and should be case insensitive (i.e. 'q' and 'Q' are the same).
Check to make sure that the position, if required, is valid. If not, print and error message and return to the main menu.
For the Insert Course and Set Load commands, if the input information is valid, construct the object accordingly. Otherwise, print an error message and return to the main menu.
You may assume Strings are at most 25 characters long.
OUTPUT FORMAT:
Each command should output the result (as shown in sample IO below) after each operation is performed.
All menu operations must be accompanied by a message indicating what operation was performed and whether or not it was successful.
All lists must be printed in a nice and tabular form as shown in the sample output. You may use C style formatting as shown in the following example. The example below shows two different ways of displaying the name and address at pre-specified positions 21, 26, 19, and 6 spaces wide. If the '-' flag is given, then it will be left-justified (padding will be on the right), else the region is right-justified. The 's' identifier is for strings, the 'd' identifier is for integers. Giving the additional '0' flag pads an integer with additional zeroes in front.
HINTS:
Remember that the position parameter to all of the methods in the TrainLinkedList class refers to the position of a TrainCar within the list (starting at position 1).
SAMPLE INPUT/OUTPUT:
// Comment in green, input in red, output in black
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: I
Enter car length in meters: 15.0
Enter car weight in tons: 10.0
New train car 15.0 meters 10.0 tons inserted into train.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: L
Enter produce name: Corn
Enter product weight in tons: 100.0
Enter prduct value in dollars: 15440
Enter is product dangerous? (y/n): n
100.0 tons of Corn added to the current car.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: I
Enter car length in meters: 18.5
Enter car weight in tons: 8.3
New train car 18.5 meters 8.3 tons inserted into train.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: L
Enter product name: Corn
Enter product weight in tons: 85.0
Enter prduct value in dollars: 13120
Enter is product dangerous? (y/n): n
85.0 tons of Corn added to the current car.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: T
Train: 2 cars, 33.5 meters, 203.3 tons, $28,560.00 value, not dangerous.
// Menu not shown in sample i/o
Enter a selection: F
No next car, cannot move cursor forward.
// Menu not shown in sample i/o
Enter a selection: B
Cursor moved backward
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: I
Enter car length in meters: 32.1
Enter car weight in tons: 17.4
New train car 32.1 meters 17.4 tons inserted into train.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: L
Enter produce name: TNT
Enter product weight in tons: 25.0
Enter prduct value in dollars: 151500
Enter is product dangerous? (y/n): y
25.3 tons of TNT added to the current car.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: T
Train: 3 cars, 65.6 meters, 246.0 tons, $180,060.00 value, DANGEROUS.
// Menu not shown in sample i/o
Enter a selection: F
Enter product name: Corn
The following products were found on 2 cars:
// Menu not shown in sample i/o
Enter a selection: F
Enter product name: Milk
No record of Milk on board train.
// Menu not shown in sample i/o
Enter a selection: D
Dangerous cars successfully removed from the train.
// Menu not shown in sample i/o
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: R
Car successully unlinked. The following load has been removed from the train:
Enter a selection: M
// Menu not shown in sample i/o
Enter a selection: Q
Program terminating successfully..
wraps contains TrainCarNode TrainCar ProductLoad members - prev TrainCarNode members members carLength: double carWeight: double - load ProductLoad name String weight: double value double -isDangerous: boolean next: TrainCarNode car TrainCar constructors: constructors TrainCarNode() +TrainCarNode(car TrainCar) TrainCar(carWeight double carLength: double) constructors + ProductLoad(name String getters/ setters: All member variables. weight: double, value double, isDangerous: boolean) getters Isetters +getCarWeight0 double + getCarLength0 dobule +getProductLoad0 ProductLoad +setProductLoad(load ProductLoad) : void methods + toString) String getters Isetters All member variables. methods: +isEmpty): booleanExplanation / Answer
Below is your code: -
ProductLoad.java
public class ProductLoad {
private String name;
private double weight;
private double value;
private boolean dangerous;
/**
* Creates a new ProductLoad object with uninstantiated parameters
*/
public ProductLoad() {
}
/**
* Creates a new ProductLoad object using given values. Overloaded
* constructor
*
* @param name
* full name of the ProductLoad
* @param weight
* weight value of the ProductLoad in decimal
* @param value
* value of the ProductLoad in decimal
* @param dangerous
* indicates whether or not the ProductLoad is dangerous
*/
public ProductLoad(String name, double weight, double value, boolean dangerous) throws IllegalArgumentException {
if (weight < 0)
throw new IllegalArgumentException("Invalid Entry for weight (negative).");
if (value < 0)
throw new IllegalArgumentException("Invalid Entry for value (negative).");
this.name = name;
this.weight = weight;
this.value = value;
this.dangerous = dangerous;
}
/**
* Changes a particular ProductLoad's name to a new specified name
*
* @param name
* new name of the ProductLoad
*/
public void setName(String name) {
this.name = name;
}
/**
* Receives the name of a particular ProductLoad
*
* @return the name of a ProductLoad as a String
*/
public String getName() {
return name;
}
/**
* Changes a particular ProductLoad's weight value to a new specified weight
* value
*
* @param weight
* new weight value of the ProductLoad
* @throws IllegalArgumentException
* indicates that the weight is an invalid entry (negative
* value).
*/
public void setWeight(double weight) throws IllegalArgumentException {
if (weight < 0)
throw new IllegalArgumentException("Invalid entry for weight (negative).");
this.weight = weight;
}
/**
* Receives the weight value of a particular ProductLoad
*
* @return the weight value of a ProductLoad as a double
*/
public double getWeight() {
return weight;
}
/**
* Changes a particular ProductLoad's value to a new specified value
*
* @param value
* new value of the ProductLoad
* @throws IllegalArgumentException
* indicates that value is an invalid entry (negative value)
*/
public void setValue(double value) throws IllegalArgumentException {
if (value < 0)
throw new IllegalArgumentException("Invalid entry for value (negative).");
this.value = value;
}
/**
* Receives the value of a particular ProductLoad
*
* @return the value of a ProductLoad as a double
*/
public double getValue() {
return value;
}
/**
* Changes a particular ProductLoad's indication of danger
*
* @param dangerous
* new indication of whether or not the product is dangerous
*/
public void setDangerous(boolean dangerous) {
this.dangerous = dangerous;
}
/**
* Receives the danger status of a particular ProductLoad
*
* @return the indication of a dangerous ProductLoad as a boolean
*/
public boolean getDangerous() {
return dangerous;
}
}
TrainCarNode.java
public class TrainCarNode {
private TrainCarNode prev;
private TrainCarNode next;
private TrainCar car;
/**
* Creates a new TrainCarNode object with uninstantiated parameters
*/
public TrainCarNode() {
}
/**
* Creates a new TrainCarNode using given values.
*
* @param car
* new TrainCar of the TrainCarNode
*/
public TrainCarNode(TrainCar car) {
this.prev = null;
this.next = null;
this.car = car;
}
/**
* Changes a particular TrainCarNode's previous TrainCarNode to a new
* specified TrainCarNode
*
* @param prev
* new previous TrainCarNode of the current TrainCarNode
*/
public void setPrev(TrainCarNode prev) {
this.prev = prev;
}
/**
* Receives the previous TrainCarNode of a particular TrainCarNode
*
* @return the previous TrainCarNode of a particular TrainCarNode
*/
public TrainCarNode getPrev() {
return prev;
}
/**
* Changes a particular TrainCarNode's next TrainCarNode to a new specified
* TrainCarNode
*
* @param next
* new next TrainCarNode of the current TrainCarNode
*/
public void setNext(TrainCarNode next) {
this.next = next;
}
/**
* Receives the next TrainCarNode of a particular TrainCarNode
*
* @return the next TrainCarNode of a particular TrainCarNode
*/
public TrainCarNode getNext() {
return next;
}
/**
* Changes a particular TrainCarNode's TrainCar
*
* @param car
* new TrainCar of the TrainCarNode
*/
public void setCar(TrainCar car) {
this.car = car;
}
/**
* Receives the TrainCar of a particular TrainCarNode
*
* @return the car of a TrainCarNode as a TrainCar object
*/
public TrainCar getCar() {
return car;
}
/**
* Obtains the String representation of this TrainCarNode object, which is a
* neatly formatted output of the content of a particular TrainCarNode
*
* @return the representation of this TrainCarNode object as a String
*/
public String toString() {
// String a = "Previous TrainCarNode: ";
// String b = "Next TrainCarNode: ";
String c = "TrainCar: ";
String d = " Length(m): ";
String e = " Weight (t): ";
String f = " Load: ";
String g = " Name: ";
String h = " Weight: ";
String i = " Value: ";
String j = " Dangerous: ";
/*
* a+getPrev()+" "+ b+getNext()+
*/
return (" " + c + " " + d + car.getCarLength() + " " + e + car.getCarWeight() + " " + f + " " + g
+ car.getProductLoad().getName() + " " + h + car.getProductLoad().getWeight() + " " + i
+ car.getProductLoad().getValue() + " " + j + car.getProductLoad().getDangerous() + " ");
}
}
TrainCar.java
public class TrainCar {
private double carLength;
private double carWeight;
private ProductLoad load;
/**
* Creates a new TrainCar object with uninstantiated parameters
*/
public TrainCar() {
}
/**
* Creates a new TrainCar object using given values.
*
* @param carLength
* length value of the car
* @param carWeight
* weight value of the car
*/
public TrainCar(double carLength, double carWeight) throws IllegalArgumentException {
if (carLength < 0)
throw new IllegalArgumentException("Invalid entry for carLength; negative value.");
if (carWeight < 0)
throw new IllegalArgumentException("Invalid entry for carWeight; negative value.");
this.carLength = carLength;
this.carWeight = carWeight;
}
/**
* Creates a new TrainCar object using given values. Overload Constructor
*
* @param carLength
* length value of the car
* @param carWeight
* weight value of the car
* @param load
* the ProductLoad object being carried by the car
*/
public TrainCar(double carLength, double carWeight, ProductLoad load) {
this.carLength = carLength;
this.carWeight = carWeight;
this.load = load;
}
/**
* Receives the car length of a particular TrainCar
*
* @return the car length value of a TrainCar as a double
*/
public double getCarLength() {
return carLength;
}
/**
* Receives the car weight value of a particular TrainCar
*
* @return the car weight of a TrainCar as a double
*/
public double getCarWeight() {
return carWeight;
}
/**
* Receives the ProductLoad object of a particular TrainCar
*
* @return the ProductLoad object of a TrainCar
*/
public ProductLoad getProductLoad() {
return load;
}
/**
* Changes a particular TrainCar's ProductLoad to a new specified
* ProductLoad
*
* @param load
* new load of the TrainCar
*/
public void setProductLoad(ProductLoad load) {
this.load = load;
}
/**
* Determines whether the car is empty or not
*
* @return the indication of an empty TrainCar as a boolean
*/
public boolean isEmpty() {
if (load == null)
return true;
else
return false;
}
}
TrainLinkedList.java
public class TrainLinkedList {
private TrainCarNode head;
private TrainCarNode tail;
private TrainCarNode cursor;
private int size;
private double totalLength;
private double totalWeight;
private double totalValue;
private int isDangerous;
private String search;
/**
* Constructs an instance of the TrainLinkedList with no TrainCar objects in
* it
*/
public TrainLinkedList() {
size = 0;
totalLength = 0;
totalWeight = 0;
isDangerous = 0;
search = "";
head = null;
tail = null;
cursor = null;
}
/**
* Returns a reference to the TrainCar at the node currently referenced by
* the cursor
*/
public TrainCar getCursorData() throws Exception {
if (cursor == null)
throw new Exception("Cursor is null.");
return cursor.getCar();
}
/**
* Places car in the node currently referenced by the cursor
*/
public void setCursorData(TrainCar car) throws Exception {
if (cursor != null)
cursor.setCar(car);
else
throw new Exception("The list is empty; cursor is null.");
}
/**
* Moves the cursor to point at the previous TrainCarNode
*/
public void cursorBackward() throws Exception {
if (cursor != null && cursor != head) {
cursor = cursor.getPrev();
}
else
throw new Exception(" No previous car, cannot move cursor backward.");
}
/**
* Moves the cursor to point at the next TrainCarNode
*/
public void cursorForward() throws Exception {
if (cursor != null && cursor != tail) {
cursor = cursor.getNext();
}
else
throw new Exception(" No next car, cannot move cursor forward.");
}
/**
* Inserts a car into the train after the cursor position
*
*/
public void insertAfterCursor(TrainCar newCar) throws IllegalArgumentException {
if (newCar != null) {
TrainCarNode newNode = new TrainCarNode(newCar);
if (cursor == null) {
size++;
totalLength += newCar.getCarLength();
totalWeight += newCar.getCarWeight();
if (newCar.getProductLoad() != null) {
totalWeight += newCar.getProductLoad().getWeight();
totalValue += newCar.getProductLoad().getValue();
if (newCar.getProductLoad().getDangerous())
isDangerous++;
}
newNode.setNext(null);
newNode.setPrev(null);
cursor = newNode;
head = newNode;
tail = newNode;
}
else if (cursor == tail) {
size++;
totalLength += newCar.getCarLength();
totalWeight += newCar.getCarWeight();
if (newCar.getProductLoad() != null) {
totalWeight += newCar.getProductLoad().getWeight();
totalValue += newCar.getProductLoad().getValue();
if (newCar.getProductLoad().getDangerous())
isDangerous++;
}
newNode.setNext(null);
newNode.setPrev(cursor);
cursor.setNext(newNode);
tail = newNode;
cursor = tail;
}
else {
size++;
totalLength += newCar.getCarLength();
totalWeight += newCar.getCarWeight();
if (newCar.getProductLoad() != null) {
totalWeight += newCar.getProductLoad().getWeight();
totalValue += newCar.getProductLoad().getValue();
if (newCar.getProductLoad().getDangerous())
isDangerous++;
}
newNode.setNext(cursor.getNext());
newNode.setPrev(cursor);
cursor.setNext(newNode);
newNode.getNext().setPrev(newNode);
cursor = newNode;
}
}
else
throw new IllegalArgumentException("newCar is null.");
}
/**
* Removes the TrainCarNode referenced by the cursor and returns the
* TrainCar contained within the node
*/
public TrainCar removeCursor() throws Exception {
TrainCar removedNode = null;
if (cursor != null) {
removedNode = cursor.getCar();
if (cursor == head) {
if (cursor == tail) {
cursor = null;
tail = null;
head = null;
size = 0;
totalLength = 0;
totalWeight = 0;
totalWeight = 0;
totalValue = 0;
isDangerous = 0;
}
else {
size--;
totalLength -= cursor.getCar().getCarLength();
totalWeight -= cursor.getCar().getCarWeight();
if (cursor.getCar().getProductLoad() != null) {
totalWeight -= cursor.getCar().getProductLoad().getWeight();
totalValue -= cursor.getCar().getProductLoad().getValue();
if (cursor.getCar().getProductLoad().getDangerous())
isDangerous--;
}
cursorForward();
cursor.setPrev(null);
head = cursor;
}
}
else if (cursor == tail) {
size--;
totalLength -= cursor.getCar().getCarLength();
totalWeight -= cursor.getCar().getCarWeight();
if (cursor.getCar().getProductLoad() != null) {
totalWeight -= cursor.getCar().getProductLoad().getWeight();
totalValue -= cursor.getCar().getProductLoad().getValue();
if (cursor.getCar().getProductLoad().getDangerous())
isDangerous--;
}
cursorBackward();
// cursor.getNext().setPrev(null);
cursor.setNext(null);
tail = cursor;
}
else {
size--;
totalLength -= cursor.getCar().getCarLength();
totalWeight -= cursor.getCar().getCarWeight();
if (cursor.getCar().getProductLoad() != null) {
totalWeight -= cursor.getCar().getProductLoad().getWeight();
totalValue -= cursor.getCar().getProductLoad().getValue();
if (cursor.getCar().getProductLoad().getDangerous())
isDangerous--;
}
cursorForward();
cursor.getPrev().getPrev().setNext(cursor);
cursor.setPrev(cursor.getPrev().getPrev());
}
}
else
throw new Exception("Empty List.");
return removedNode;
}
/**
* Determines the number of TrainCar objects currently on the train
* <p>
* Notes: This function should complete in O(1) time
* </p>
*
* @return the number of TrainCar objects on this train
*/
public int size() {
return size;
}
/**
* Returns the total length of the train in meters
* <p>
* Notes: This function should complete in O(1) time
* </p>
*
* @return the sum of the lengths of each TrainCar in the train
*/
public double getLength() {
return totalLength;
}
/**
* Returns the total value of product carried by the train
* <p>
* Notes: This function should complete in O(1) time
* </p>
*
* @return the sum of the values of each TrainCar in the train
*/
public double getValue() {
return totalValue;
}
/**
* Returns the total weight in tons of the train
* <p>
* Notes: This function should complete in O(1) time
* </p>
*
* @return the sum of the weight of each TrainCar plus the sum of the
* ProductLoad carried by that car
*/
public double getWeight() {
return totalWeight;
}
/**
* Whether or not there is a dangerous product on one of the TrainCar
* objects on the train
* <p>
* Notes: This function should complete in O(1) time
* </p>
*
* @return returns true if the train contains at least one TrainCar carrying
* a dangerous ProductLoad, false otherwise
*/
public boolean isDangerous() {
if (isDangerous > 0)
return true;
return false;
}
/**
* Searches the list for all ProductLoad objects with the indicated name,
* sums together their weight and value, obtains its danger status, and
* prints a single ProductLoad record to the console
*
* @param name
* the name of the ProductLoad to find on the train
*/
public void findProduct(String name) {
double cursorWeight = 0;
double cursorValue = 0;
boolean cursorDanger = false;
boolean firstMatch = false;
TrainCarNode tempCursor = new TrainCarNode();
tempCursor = head;
int count = 0;
search = "";
while (tempCursor != null) {
if (tempCursor.getCar().getProductLoad() == null)
break;
if ((tempCursor.getCar().getProductLoad().getName()).equals(name)) {
if (firstMatch == false) {
cursorDanger = tempCursor.getCar().getProductLoad().getDangerous();
firstMatch = true;
}
cursorWeight += tempCursor.getCar().getProductLoad().getWeight();
cursorValue += tempCursor.getCar().getProductLoad().getValue();
count++;
}
tempCursor = tempCursor.getNext();
}
if (firstMatch == false) {
System.out.println(" There are no ProductLoad objects of the indicated name on board the train.");
System.out.println("No record of " + name + " on board train.");
search = (" There are no ProductLoad objects of the indicated name on board the train. ")
+ ("No record of " + name + " on board train. ");
}
else {
System.out.println(" The following products were found on " + count + " cars: ");
search = (" The following products were found on " + count + " cars: ");
System.out.println();
System.out.println(" Name Weight (t) Value ($) Dangerous");
search += (" Name Weight (t) Value ($) Dangerous ");
System.out.println("=============================================================");
search += ("============================================================= ");
String danger = (cursorDanger) ? "YES" : "NO";
System.out.printf(" %-15s%-16.1f%,-16.2f%-7s ", name, cursorWeight, cursorValue, danger);
search += String.format(" %-15s%-16.1f%,-16.2f%-7s ", name, cursorWeight, cursorValue, danger);
}
}
/**
* Prints a neatly formatted table of the car number, car length, car
* weight, load name, load weight, load value, and load dangerousness for
* all of the car on the train.
*/
public void printManifest() {
TrainCarNode temp = head;
int num = 1;
System.out.println();
System.out.println(" CAR: LOAD:");
System.out.println(" Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous");
System.out.println(
"====================================+===============================================================");
while (temp != null) {
if (temp == cursor)
System.out.printf(" -> %-7d%-13.1f%-11.1f| %-18s%-16.1f%,-16.2f%s ", num,
temp.getCar().getCarLength(), temp.getCar().getCarWeight(),
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getName() : "Empty",
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getWeight() : 0,
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getValue() : 0,
(temp.getCar().getProductLoad() != null && temp.getCar().getProductLoad().getDangerous())
? "YES" : "NO");
else
System.out.printf(" %-7d%-13.1f%-11.1f| %-18s%-16.1f%,-16.2f%s ", num,
temp.getCar().getCarLength(), temp.getCar().getCarWeight(),
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getName() : "Empty",
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getWeight() : 0,
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getValue() : 0,
(temp.getCar().getProductLoad() != null && temp.getCar().getProductLoad().getDangerous())
? "YES" : "NO");
temp = temp.getNext();
num++;
}
}
/**
* Removes all dangerous cars from the train, maintaining the order of the
* cars in the train
* <dt><b>Postconditions:</b>
* <dd>all dangerous cars have been removed from this train; the order of
* all non-dangerous cars must be maintained upon the completion of this
* method
*
* @throws Exception
* indicates that cursor removal failed
*/
public void removeDangerousCars() throws Exception {
cursor = head;
TrainCar removed = null;
while (cursor != null) {
if (cursor.getCar().getProductLoad() != null) {
if (cursor.getCar().getProductLoad().getDangerous())
removed = removeCursor();
}
if (cursor == tail)
break;
cursorForward();
}
if (removed == null)
System.out.println(" The train contains no dangerous cars.");
else
System.out.println(" Dangerous cars successfully removed from the train.");
}
/**
* Returns a neatly formatted String representation of the train
*
* @return a neatly formatted string containing information about the train,
* including it's size (number of cars), length in meters, weight in
* tons, value in dollars, and whether it is dangerous or not
*/
public String toString() {
return (String.format(" Train: %d cars, %.1f meters, %.1f tons, $%,.2f value, %s.", size, totalLength,
totalWeight, totalValue, (isDangerous > 0) ? "DANGEROUS" : "not dangerous"));
}
/**
* Increments totalWeight variable from added ProductLoad weight
*
* @param prodWeight
* added ProductLoad weight
*/
public void addProdWeight(double prodWeight) {
totalWeight += prodWeight;
}
/**
* Decrements totalWeight variable from replaced ProductLoad weight
*
* @param prodWeight
* subtracted ProductLoad weight
*/
public void decProdWeight(double prodWeight) {
totalWeight -= prodWeight;
}
/**
* Increments totalValue variable from added ProductLoad value
*
* @param prodValue
* added ProductLoad value
*/
public void addProdValue(double prodValue) {
totalValue += prodValue;
}
/**
* Decrements totalValue variable from replaced/removed ProductLoad value
*
* @param prodValue
* subtracted ProductLoad value
*/
public void decProdValue(double prodValue) {
totalValue -= prodValue;
}
/**
* Increments private variable isDangerous to indicate product danger
*/
public void addDanger() {
isDangerous++;
}
/**
* Decrements private variable isDangerous to indicate that a product which
* was dangerous was removed.
*/
public void decDanger() {
isDangerous--;
}
/**
* Returns the the Manifest Display from the printManifest() method
*
* @return a neatly formatted table displayed in printManifest() as a String
*/
public String manifestString() {
TrainCarNode temp = head;
int num = 1;
String a = " ";
String b = (" CAR: LOAD: ");
String c = (" Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous ");
String d = ("====================================+=============================================================== ");
String e = "";
while (temp != null) {
if (temp == cursor)
e += String.format(" -> %-7d%-13.1f%-11.1f| %-18s%-16.1f%,-16.2f%s ", num,
temp.getCar().getCarLength(), temp.getCar().getCarWeight(),
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getName() : "Empty",
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getWeight() : 0,
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getValue() : 0,
(temp.getCar().getProductLoad() != null && temp.getCar().getProductLoad().getDangerous())
? "YES" : "NO");
else
e += String.format(" %-7d%-13.1f%-11.1f| %-18s%-16.1f%,-16.2f%s ", num,
temp.getCar().getCarLength(), temp.getCar().getCarWeight(),
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getName() : "Empty",
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getWeight() : 0,
(temp.getCar().getProductLoad() != null) ? temp.getCar().getProductLoad().getValue() : 0,
(temp.getCar().getProductLoad() != null && temp.getCar().getProductLoad().getDangerous())
? "YES" : "NO");
temp = temp.getNext();
num++;
}
return a + b + c + d + e;
}
/**
* Returns a String version of the table output for findProduct(String name)
* method
*
* @return returns a neatly formatted table displayed in the
* findProduct(String name) method as a String
*/
public String searchProdString() {
return search;
}
}
TrainManager.java
public class TrainManager {
/**
* The main method runs a menu driver application which first creates an
* empty TrainLinkedList object; the program prompts the user for a command
* to execute an operation in accordance to the menu
*
*/
public static void main(String[] args) throws IllegalArgumentException, Exception {
TrainLinkedList train = new TrainLinkedList();
Scanner in = new Scanner(System.in); // Scanner for user-input
boolean cont = true;
String selection = "";
char selChar = ' ';
while (cont == true) { // program will continue as long as cont remains
// true
// Main menu of program
System.out.println();
System.out.println("(F) Cursor Forward");
System.out.println("(B) Cursor Backward");
System.out.println("(I) Insert Car After Cursor");
System.out.println("(R) Remove Car At Cursor");
System.out.println("(L) Set Product Load");
System.out.println("(S) Search For Product");
System.out.println("(T) Display Train");
System.out.println("(M) Display Manifest");
System.out.println("(D) Remove Dangerous Cars");
System.out.println("(Q) Quit");
System.out.println();
System.out.print("Enter a selection: ");
selection = in.nextLine().toUpperCase();
selChar = selection.charAt(0); // reads char at position 0 of
// String, which should be expected
// to be only one character
if (selection.length() > 1)
System.out.println(" Invalid Entry, please try again.");
// Goes on to the switch statement in accordance to user-input char
else {
switch (selChar) {
case 'F':
try {
train.cursorForward();
System.out.println(" Cursor moved forward.");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
break;
case 'B':
try {
train.cursorBackward();
System.out.println(" Cursor moved backward.");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
break;
case 'I':
System.out.println();
System.out.print("Enter car length in meters: ");
double carLen = in.nextDouble();
in.nextLine();
System.out.print("Enter car weight in tons: ");
double carWeight = in.nextDouble();
in.nextLine();
try {
TrainCar insert = new TrainCar(carLen, carWeight);
train.insertAfterCursor(insert);
System.out.printf(" New train car %.1f meters %.1f tons " + "inserted into train. ", carLen,
carWeight);
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
}
break;
case 'R':
try {
TrainCar removedCar = train.removeCursor();
System.out.println(
"Car successfully unlinked. The following load has been removed from the train: ");
System.out.println();
System.out.println(" Name Weight (t) Value ($) Dangerous");
System.out.println("=============================================================");
String danger = (removedCar.getProductLoad() != null
&& removedCar.getProductLoad().getDangerous()) ? "YES" : "NO";
System.out.printf(" %-15s%-16.1f%,-16.2f%-7s ",
(removedCar.getProductLoad() != null) ? removedCar.getProductLoad().getName() : "Empty",
(removedCar.getProductLoad() != null) ? removedCar.getProductLoad().getWeight() : 0,
(removedCar.getProductLoad() != null) ? removedCar.getProductLoad().getValue() : 0,
danger);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
break;
case 'L':
System.out.println();
System.out.print("Enter product name: ");
String prodName = in.nextLine();
System.out.print("Enter product weight in tons: ");
double prodWeight = in.nextDouble();
in.nextLine();
System.out.print("Enter product value in dollars: ");
double prodValue = in.nextDouble();
in.nextLine();
System.out.print("Enter is product dangerous? (y/n): ");
String dangerousInput = in.nextLine();
char dangerousCheck = dangerousInput.charAt(0);
switch (dangerousCheck) {
case 'y':
try {
if (train.getCursorData().getProductLoad() != null) {
train.decProdWeight(train.getCursorData().getProductLoad().getWeight());
train.decProdValue(train.getCursorData().getProductLoad().getValue());
if (train.getCursorData().getProductLoad().getDangerous())
train.decDanger();
}
ProductLoad tempLoadDangY = new ProductLoad(prodName, prodWeight, prodValue, true);
train.getCursorData().setProductLoad(tempLoadDangY);
train.addProdWeight(prodWeight);
train.addProdValue(prodValue);
train.addDanger();
System.out.println();
System.out.println(prodWeight + " tons of " + prodName + " added to the current car.");
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
break;
case 'n':
try {
ProductLoad tempLoadDangN = new ProductLoad(prodName, prodWeight, prodValue, false);
train.addProdWeight(prodWeight);
train.addProdValue(prodValue);
train.getCursorData().setProductLoad(tempLoadDangN);
System.out.println();
System.out.println(prodWeight + " tons of " + prodName + " added to the current car.");
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
break;
default:
System.out.println("Invalid input for product danger input.");
break;
}
break;
case 'S':
System.out.println();
System.out.print("Enter product name: ");
String productName = in.nextLine();
train.findProduct(productName);
break;
case 'T':
System.out.println(train.toString());
break;
case 'M':
train.printManifest();
break;
case 'D':
try {
train.removeDangerousCars();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
break;
case 'Q':
cont = false;
System.out.println("Program terminating successfully...");
break;
default:
System.out.println("Invalid Entry, please try again.");
break;
}
}
// System.out.println(train.toString());
}
}
}
Output
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: I
Enter car length in meters: 15
Enter car weight in tons: 10.0
New train car 15.0 meters 10.0 tons inserted into train.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
-> 1 15.0 10.0 | Empty 0.0 0.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: L
Enter product name: Corn
Enter product weight in tons: 100.0
Enter product value in dollars: 15440
Enter is product dangerous? (y/n): n
100.0 tons of Corn added to the current car.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
-> 1 15.0 10.0 | Corn 100.0 15,440.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: I
Enter car length in meters: 18.5
Enter car weight in tons: 8.3
New train car 18.5 meters 8.3 tons inserted into train.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
1 15.0 10.0 | Corn 100.0 15,440.00 NO
-> 2 18.5 8.3 | Empty 0.0 0.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: L
Enter product name: Corn
Enter product weight in tons: 85
Enter product value in dollars: 13120
Enter is product dangerous? (y/n): n
85.0 tons of Corn added to the current car.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
1 15.0 10.0 | Corn 100.0 15,440.00 NO
-> 2 18.5 8.3 | Corn 85.0 13,120.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: T
Train: 2 cars, 33.5 meters, 203.3 tons, $28,560.00 value, not dangerous.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: F
No next car, cannot move cursor forward.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: B
Cursor moved backward.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
-> 1 15.0 10.0 | Corn 100.0 15,440.00 NO
2 18.5 8.3 | Corn 85.0 13,120.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: I
Enter car length in meters: 32.1
Enter car weight in tons: 17.4
New train car 32.1 meters 17.4 tons inserted into train.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
1 15.0 10.0 | Corn 100.0 15,440.00 NO
-> 2 32.1 17.4 | Empty 0.0 0.00 NO
3 18.5 8.3 | Corn 85.0 13,120.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: L
Enter product name: TNT
Enter product weight in tons: 25.0
Enter product value in dollars: 151500
Enter is product dangerous? (y/n): y
25.0 tons of TNT added to the current car.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
1 15.0 10.0 | Corn 100.0 15,440.00 NO
-> 2 32.1 17.4 | TNT 25.0 151,500.00 YES
3 18.5 8.3 | Corn 85.0 13,120.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: T
Train: 3 cars, 65.6 meters, 245.7 tons, $180,060.00 value, DANGEROUS.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: F
Cursor moved forward.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: S
Enter product name: Milk
There are no ProductLoad objects of the indicated name on board the train.
No record of Milk on board train.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: D
Dangerous cars successfully removed from the train.
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
1 15.0 10.0 | Corn 100.0 15,440.00 NO
-> 2 18.5 8.3 | Corn 85.0 13,120.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: R
Car successfully unlinked. The following load has been removed from the train:
Name Weight (t) Value ($) Dangerous
=============================================================
Corn 85.0 13,120.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: M
CAR: LOAD:
Num Length (m) Weight (t) | Name Weight (t) Value ($) Dangerous
====================================+===============================================================
-> 1 15.0 10.0 | Corn 100.0 15,440.00 NO
(F) Cursor Forward
(B) Cursor Backward
(I) Insert Car After Cursor
(R) Remove Car At Cursor
(L) Set Product Load
(S) Search For Product
(T) Display Train
(M) Display Manifest
(D) Remove Dangerous Cars
(Q) Quit
Enter a selection: Q
Program terminating successfully...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.