-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentFive.java
More file actions
63 lines (55 loc) · 1.94 KB
/
AssignmentFive.java
File metadata and controls
63 lines (55 loc) · 1.94 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
import java.util.Scanner;
public class AssignmentFive {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[][] vipCars = new String[5][4];
String[][] cheapCars = new String[5][4];
int vipIndex = 0;
int cheapIndex = 0;
for (int i = 0; i < 5; i++) {
System.out.print("Enter the price of car " + (i + 1) + ": ");
int price = scanner.nextInt();
if (price > 70000) {
if (vipIndex < vipCars.length) {
vipCars[vipIndex][0] = String.valueOf(price);
vipCars[vipIndex][1] = "VIP";
vipCars[vipIndex][2] = "2024";
vipCars[vipIndex][3] = "pre-order";
vipIndex++;
}
} else {
if (cheapIndex < cheapCars.length) {
cheapCars[cheapIndex][0] = String.valueOf(price);
cheapCars[cheapIndex][1] = "Cheap";
cheapCars[cheapIndex][2] = "old";
cheapCars[cheapIndex][3] = "for sale";
cheapIndex++;
}
}
}
System.out.println("VIP Cars:");
for (String[] row : vipCars) {
if (row[0] != null) {
for (String cell : row) {
System.out.print(cell + " ");
}
System.out.println();
}
}
System.out.println("Cheap Cars:");
boolean hasCheapCars = false;
for (String[] row : cheapCars) {
if (row[0] != null) {
hasCheapCars = true;
for (String cell : row) {
System.out.print(cell + " ");
}
System.out.println();
}
}
if (!hasCheapCars) {
System.out.println("No cheap cars available.");
}
scanner.close();
}
}