-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleTest.java
More file actions
79 lines (61 loc) · 2.65 KB
/
VehicleTest.java
File metadata and controls
79 lines (61 loc) · 2.65 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
import java.util.*;
public class VehicleTest {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of vehicles");
int numberOfVehicle = scanner.nextInt();
Vehicle vehicle[] = new Vehicle[numberOfVehicle];
for (int i = 0; i < numberOfVehicle; i++) {
vehicle[i] = new Vehicle();
}
Vehicle vehiclecons = new Vehicle("0");
for (int i = 0; i < numberOfVehicle; i++) {
System.out.println("Enter the name of vehicle " + (i + 1) + "'s initial owner");
vehiclecons.setInitialOwnerName(scanner.next());
System.out.println("Enter the name of vehicle " + (i + 1) + "'s owner");
vehicle[i].setOwnerName(scanner.next());
System.out.println("Enter current speed of vehicle " + (i + 1));
vehicle[i].setSpeed(scanner.nextInt());
System.out.println("Enter current direction of vehicle " + (i + 1));
vehicle[i].setDirection(scanner.nextInt());
// Condition for turning on or changing the direction of vehicle
System.out.println("do you want to turn?");
{
String answerTurn = scanner.next();
if (answerTurn.equals("Yes") || answerTurn.equals("yes") || answerTurn.equals("YES")) {
System.out.println("left or right?");
String answerTurnValue = scanner.next();
if (answerTurnValue.equals("left")) {
System.out.println("By what value you want to change?");
int change = scanner.nextInt();
if (change >= 180) {
System.out.println("Invalid Input");
System.exit(0);
} else {
vehicle[i].changeDirection(change);
}
}
if (answerTurnValue.equals("right")) {
System.out.println("By what value you want to change?");
int change = scanner.nextInt();
if (change >= 180) {
System.out.println("Invalid Input");
System.exit(0);
} else {
vehicle[i].changeDirection(0 - change);
}
}
}
}
}
for (int i = 0; i < numberOfVehicle; i++) {
System.out.println(
"the initial owner's name of " + (i + 1) + " vehicle is " + vehiclecons.getInitialOwnerName());
System.out.println("the name of vehicle " + (i + 1) + "'s owner is " + vehicle[i].getOwnerName());
System.out.println("current speed of vehicle " + (i + 1) + " is " + vehicle[i].getSpeed());
System.out.println("current direction of vehicle " + (i + 1) + " is " + vehicle[i].getDirection());
System.out.println("identification number of vehicle " + (i + 1) + " is " + vehicle[i].getVehicleIdNo());
}
System.out.println("The highest Idenmtification number so far is " + Vehicle.getIdentificationNumber());
}
}