Given Trolley.java and Ride.java, I'm having some issues producing the correct outputs. In the driver below, I should be getting: ------Inspect Trolley----- false Trolley Trolley1 has driven 12 loops and has earned $26.40. This trolley is at Station D. Next up is Station E. true Trolley Trolley1 has driven 0 loops and has earned $26.40. This trolley is at Station D. Next up is Station E. true Trolley Trolley2 has driven 0 loops and has earned $60.00. This trolley is at Station 3. Next up is Station 1. -----Move Trolley----- Trolley Trolley1 has driven 1 loops and has earned $26.40. This trolley is at Station D. Next up is Station E. Trolley Trolley1 has driven 50 loops and has earned $26.40. This trolley is at Station B. Next up is Station C. Trolley Trolley2 has driven 81 loops and has earned $60.00. This trolley is at Station 3. Next up is Station 1. However, I'm getting false false false, leading to the wrong loops driven in 'Inspect Trolley' and in 'Move Trolley' my loops driven is skewed to 13, 61, and 102. All the money increments seem to be correct however. public class Driver { public static void main(String[] args) { System.out.println("\n-----Inspect Ride-----"); String[] inspect1 = new String[] {"asdfasd", "asjdfl", "tracks clear"}; String[] inspect2 = new String[] {"asdfasd", "asdfjk", "brakes oK", "gas tAnk not empty"}; String[] inspect3 = new String[] {"tracks clear", "sadfjh", "braKES ok", "brAKEs OK", "gas tank not EmPTY"}; System.out.println("\n-----Trolley Test-----"); String[] line1 = new String[] {"Station A", "Station B", "Station C", "Station D", "Station E"}; String[] line2 = new String[] {"Station 1", "Station 2", "Station 3"}; Trolley normalTrolley = new Trolley("Trolley1", 10, line1, 0); Trolley normalTrolley2 = new Trolley("Trolley2", 20, line2, 2); Trolley trolleyDiffConst = new Trolley("Trolley3", line1, 3); Trolley dupTrolley = new Trolley("Trolley1", 10, line1, 0); System.out.println(normalTrolley); System.out.println(normalTrolley2); System.out.println(trolleyDiffConst); System.out.println(dupTrolley); String[] waiting1 = new String[] {"C", "D", "E"}; String[] waiting2 = new String[] {"A", "A", "B", "C"}; System.out.println("\n-----Add Passengers-----"); System.out.println(normalTrolley.addPassengers(3, waiting1)); System.out.println(normalTrolley); System.out.println(normalTrolley.getPassengerList()); System.out.println(normalTrolley.addPassengers(5, waiting2)); System.out.println(normalTrolley); System.out.println(normalTrolley.getPassengerList()); System.out.println(normalTrolley.addPassengers(-5, waiting2)); System.out.println(normalTrolley); System.out.println(normalTrolley.getPassengerList()); System.out.println("Add all 20 passengers. Additional will not be added:"); String[] waiting4 = new String[] {"A", "A", "B", "C", "A", "A", "B", "C", "A", "A", "B", "C", "A", "A", "B", "C", "A", "A", "B", "C", "A"}; System.out.println(normalTrolley2.addPassengers(3, waiting4)); System.out.println(normalTrolley2); System.out.println(normalTrolley2.getPassengerList()); System.out.println("\n-----Remove then Add Passengers-----"); System.out.println(normalTrolley.removePassenger("A")); System.out.println(normalTrolley.removePassenger("A")); System.out.println(normalTrolley.removePassenger("A")); System.out.println(normalTrolley.addPassengers(5, waiting1)); System.out.println(normalTrolley); System.out.println(normalTrolley.getPassengerList()); System.out.println("\n-----Inspect Trolley-----"); System.out.println(normalTrolley.inspectRide(inspect1)); System.out.println(normalTrolley); System.out.println(normalTrolley.inspectRide(inspect2)); System.out.println(normalTrolley); System.out.println(normalTrolley2.inspectRide(inspect2)); System.out.println(normalTrolley2); System.out.println("\n-----Move Trolley-----"); normalTrolley.moveTrolley(5); System.out.println(normalTrolley); normalTrolley.moveTrolley(243); System.out.println(normalTrolley); normalTrolley2.moveTrolley(243); System.out.println(normalTrolley2); System.out.println("\n-----Double check equals-----"); System.out.println(normalTrolley.equals(dupTrolley));; } }
Given Trolley.java and Ride.java, I'm having some issues producing the correct outputs.
In the driver below, I should be getting:
------Inspect Trolley-----
false
Trolley Trolley1 has driven 12 loops and has earned $26.40. This trolley is at Station D. Next up is Station E.
true
Trolley Trolley1 has driven 0 loops and has earned $26.40. This trolley is at Station D. Next up is Station E.
true
Trolley Trolley2 has driven 0 loops and has earned $60.00. This trolley is at Station 3. Next up is Station 1. -----Move Trolley-----
Trolley Trolley1 has driven 1 loops and has earned $26.40. This trolley is at Station D. Next up is Station E. Trolley Trolley1 has driven 50 loops and has earned $26.40. This trolley is at Station B. Next up is Station C. Trolley Trolley2 has driven 81 loops and has earned $60.00. This trolley is at Station 3. Next up is Station 1.
However, I'm getting false false false, leading to the wrong loops driven in 'Inspect Trolley' and in 'Move Trolley'
my loops driven is skewed to 13, 61, and 102. All the money increments seem to be correct however.
public static void main(String[] args) {
System.out.println("\n-----Inspect Ride-----");
String[] inspect1 = new String[] {"asdfasd", "asjdfl", "tracks clear"};
String[] inspect2 = new String[] {"asdfasd", "asdfjk", "brakes oK", "gas tAnk not empty"};
String[] inspect3 = new String[] {"tracks clear", "sadfjh", "braKES ok", "brAKEs OK", "gas tank not EmPTY"};
System.out.println("\n-----Trolley Test-----");
String[] line1 = new String[] {"Station A", "Station B", "Station C", "Station D", "Station E"};
String[] line2 = new String[] {"Station 1", "Station 2", "Station 3"};
Trolley normalTrolley = new Trolley("Trolley1", 10, line1, 0);
Trolley normalTrolley2 = new Trolley("Trolley2", 20, line2, 2);
Trolley trolleyDiffConst = new Trolley("Trolley3", line1, 3);
Trolley dupTrolley = new Trolley("Trolley1", 10, line1, 0);
System.out.println(normalTrolley);
System.out.println(normalTrolley2);
System.out.println(trolleyDiffConst);
System.out.println(dupTrolley);
String[] waiting1 = new String[] {"C", "D", "E"};
String[] waiting2 = new String[] {"A", "A", "B", "C"};
System.out.println("\n-----Add Passengers-----");
System.out.println(normalTrolley.addPassengers(3, waiting1));
System.out.println(normalTrolley);
System.out.println(normalTrolley.getPassengerList());
System.out.println(normalTrolley.addPassengers(5, waiting2));
System.out.println(normalTrolley);
System.out.println(normalTrolley.getPassengerList());
System.out.println(normalTrolley.addPassengers(-5, waiting2));
System.out.println(normalTrolley);
System.out.println(normalTrolley.getPassengerList());
System.out.println("Add all 20 passengers. Additional will not be added:");
String[] waiting4 = new String[] {"A", "A", "B", "C", "A", "A", "B", "C", "A", "A", "B", "C", "A", "A", "B",
"C", "A", "A", "B", "C", "A"};
System.out.println(normalTrolley2.addPassengers(3, waiting4));
System.out.println(normalTrolley2);
System.out.println(normalTrolley2.getPassengerList());
System.out.println("\n-----Remove then Add Passengers-----");
System.out.println(normalTrolley.removePassenger("A"));
System.out.println(normalTrolley.removePassenger("A"));
System.out.println(normalTrolley.removePassenger("A"));
System.out.println(normalTrolley.addPassengers(5, waiting1));
System.out.println(normalTrolley);
System.out.println(normalTrolley.getPassengerList());
System.out.println("\n-----Inspect Trolley-----");
System.out.println(normalTrolley.inspectRide(inspect1));
System.out.println(normalTrolley);
System.out.println(normalTrolley.inspectRide(inspect2));
System.out.println(normalTrolley);
System.out.println(normalTrolley2.inspectRide(inspect2));
System.out.println(normalTrolley2);
System.out.println("\n-----Move Trolley-----");
normalTrolley.moveTrolley(5);
System.out.println(normalTrolley);
normalTrolley.moveTrolley(243);
System.out.println(normalTrolley);
normalTrolley2.moveTrolley(243);
System.out.println(normalTrolley2);
System.out.println("\n-----Double check equals-----");
System.out.println(normalTrolley.equals(dupTrolley));;
}
}
Step by step
Solved in 6 steps with 5 images