-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
48 lines (34 loc) · 1.57 KB
/
Main.java
File metadata and controls
48 lines (34 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package RailwayTrains;
public class Main {
public static void main(String arg[]) {
//Assemble trains
Locomotive bigChief = new Locomotive(23, 5311);
Locomotive steelHorse = new Locomotive(21, 5409);
Train santaFe = new Train(bigChief);
Train rioGrandeExpress = new Train(steelHorse);
Car SFcar0 = new Car(12, 50);
Car SFcar1 = new Car(15, 75);
Car SFcar2 = new Car(20, 100);
Car RGEcar0 = new Car(13, 60);
Car RGEcar1 = new Car(18, 80);
santaFe.add(0, SFcar0);
santaFe.add(1, SFcar1);
santaFe.add(2, SFcar2);
rioGrandeExpress.add(0, RGEcar0);
rioGrandeExpress.add(1, RGEcar1);
//Print the information of trains
// System.out.println("Before change, the information of both trains: \n");
// System.out.println("Santa Fe:");
// System.out.println(santaFe.toString());
// System.out.println("Rio Grande Express: \n");
// System.out.println(rioGrandeExpress.toString());
// All cars of "Santa Fe" are taken over in the "Rio Grande Express"
rioGrandeExpress.relink(santaFe);
System.out.println("Rio Grande Express take over Santa Fe: \n");
System.out.println(rioGrandeExpress.toString());
// The carriage order in the "Rio Grande Express" is reversed.
rioGrandeExpress.revert();
System.out.println("The carriage order in the \"Rio Grande Express\" is reversed.\n");
System.out.println(rioGrandeExpress.toString());
}
}