-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp_cars.java
More file actions
88 lines (69 loc) · 1.6 KB
/
p_cars.java
File metadata and controls
88 lines (69 loc) · 1.6 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class p_mainClass {
public static void main(String[] args){
System.out.println(new fakeMain().run());
}
}
class fakeMain {
public int run(){
Car a;
Truck b;
Vehicle v;
int ret;
a = new Car();
b = new Truck();
v = a;
ret = a.makeCar(4);
System.out.println(v.move());
ret = b.makeTruck(10);
ret = this.race(a, b);
return 0;
}
public int race(Vehicle a, Vehicle b){
int distA;
int distB;
distA = 0;
distB = 0;
while(distA < 100 && distB < 100){
distA = distA + a.move();
distB = distB + b.move();
}
if(distA > distB){
System.out.println("Vehicle A wins!");
}else if(distA < distB){
System.out.println("Vehicle B wins!");
}else {
System.out.println("Its a tie!");
}
return 0;
}
}
class Vehicle {
int moveSpeed;
public int create(int speed){
moveSpeed = speed;
return 0;
}
public int getSpeed(){
return moveSpeed;
}
public int move(){
System.out.print("Zoom zoom, I went ");
System.out.print(moveSpeed);
System.out.println(" Units!");
return moveSpeed;
}
}
class Car extends Vehicle{
int people;
public int makeCar(int speed){
moveSpeed = speed * 2;
people = 1;
return 0;
}
}
class Truck extends Vehicle {
public int makeTruck(int speed){
moveSpeed = speed - 5;
return 0;
}
}