Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Generics

JamesCaron
JamesCaron 


See attachment Attachments Tags
Clarifications

Answers

Java - Train Solution

dickersonka
dickersonka 



Attached is the java train solution including source and comments Attachments
Train.zip (9 K) Download


Preview
1 2 600 24 12 24 SPEEDUP 50 SPEEDUP 20 SLOWDOWN 5 PRINT UNLOAD 1 1 UNLOAD 0 123-12-4567 PRINT REMOVECAR 1 UNLOAD 1 1 UNLOAD 1

Preview
BoxCar: 1 ----------- Contents: REMOVECAR 1 ERROR: The train has not arriaved in Chicago yet. ARRIVE REMOVECAR 1 PRINT Train Status ------------ Current Speed: 0 Minimum Speed: 10 Maximum Speed: 50 Current Position: Stopped in Chicago Current Number of Boxcars: 1

Preview
* Loads contents into boxcar * @param carContents contents to load * @return true if loaded * @throws BoxCarException */ boolean load(ICarContents carContents) throws BoxCarException{ //validates unique item int index = indexOf(carContents.getId()); if(index >= 0){ throw new BoxCarException("Invalid item, item with

Preview
*/ public class BoxCarException extends Exception {

Preview
{ this.weight = weight; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width;

Preview
item into car */ @Override boolean load(ICarContents carContents) throws BoxCarException { //validates type of cargo if(!(carContents instanceof Cargo)){ throw

Preview
public interface ICarContents

Preview
Create person */ public Person(){ } /** * Create person */ public Person(String id, String name, int age){ this.id = id; this.name = name; this.age = age;

Preview
} /** * Loads item into car */ @Override boolean load(ICarContents carContents) throws BoxCarException

Preview
carContents = new Person(id, name, age); train.logCommand("LOAD", new String[]{String.valueOf(boxCarId), id, name, String.valueOf(age)}); } else if(cargoType.equals("CARGO")){ int weight = Integer.parseInt(br.readLine()); int height = Integer.parseInt(br.readLine()); int width = Integer.parseInt(br.readLine()); int length = Integer.parseInt(br.readLine()); carContents = new Cargo(id, weight, height, width, length); train.logCommand("LOAD", new

Preview
has not arrived in " + to + " yet"); return; } //validates less than max boxcars if(this.boxCars.size() >= maxBoxcars){ log.printError("The boxcar limit has been reached"); return; } //adds to list this.boxCars.add(car); } /** *

Preview
} out.close(); }catch(Exception e){} } /** * Prints message * @param message message to print */ public void printMessage(String message){ try { PrintWriter out = new PrintWriter(new FileWriter(outputFile, true)); out.printf("%s\n", message); out.close(); }catch(Exception e){}

Screenshots
Purchase Answer