Question: Java problem thank you! Use the following file: SuburbanTrainTester.java public class SuburbanTrainTester { public static void main(String[] args) { SuburbanTrain train = new SuburbanTrain(); train.move(3);

Java problem thank you!

Java problem thank you! Use the following file: SuburbanTrainTester.java public class SuburbanTrainTester

Use the following file:

SuburbanTrainTester.java

public class SuburbanTrainTester { public static void main(String[] args) { SuburbanTrain train = new SuburbanTrain(); train.move(3); train.move(5); System.out.println("Distance to start: " + train.distanceToStart()); System.out.println("Expected: 40"); System.out.println("Distance to end: " + train.distanceToEnd()); System.out.println("Expected: 10"); train.turn(); train.move(4); train.turn(); train.move(2); System.out.println("Distance to start: " + train.distanceToStart()); System.out.println("Expected: 30"); System.out.println("Distance to end: " + train.distanceToEnd()); System.out.println("Expected: 20"); } }

Write a SuburbanTrain class. A SuburbanTrain moves along a track from the start to the end. There are stops every 5 miles. The towards the start(-direction). Write a class SuburbanTrain that models this behavior. SuburbanTrain class has a default constructor that sets the train at the start moving toward the end (+ direction). You can think of track is 50 miles long. The SuburbanTrain moves from one stop to another. It can either move toward the end (+ direction) or this as a number line with only positive numbers and zero. SuburbanTrain has these methods public void move (int numberOfStops) moves the train the specified number of stops in the current direction. Assume the user is well behaved and never tries to move beyond the start or end of the track public void turn - reverses the direction of the train. If the train was moving from start to end (+ direction), after the method executes, the train wll be moving toward the start (- direction) public int distanceToStart) -calculates the distance the train is from the start in miles public int distanceToEnd) - calculates the distance the train is from the end in miles Do not use if statements. Think about what information needs to be remembered and define instance variables to remember that information. HINT: You can represent the direction with an integer:+1 if the train is moving toward the end;-1 if it is moving towards the start the start is 15. It will probably be easiest to call the start location stop number 0 HINT: Remember that each stop is 5 miles from the previous stop. So if a train has moved 3 stops along the track, its distance from Javadoc for the class might look like this: fs* *Models a train rnning on a straight track going either direction *f

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!