forked from Amazon-Back-End-ES-03-25/lab_102
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain3.java
More file actions
56 lines (44 loc) · 2.08 KB
/
Main3.java
File metadata and controls
56 lines (44 loc) · 2.08 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
import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("¿Cuántos vehiculos tienes?");
int count = Integer.parseInt(scanner.nextLine());
Car[] cars = new Car[count];
for (int i = 0; i < count; i++) {
String type;
while (true) {
System.out.println("\nIngrese el tipo de vehiculo (sedan / utility / truck):");
type = scanner.nextLine().toLowerCase();
if (type.equals("sedan") || type.equals("utility") || type.equals("truck")) {
break;
}
System.out.println("Tipo no válido. Por favor, ingrese 'sedan', 'utility' o 'truck'.");
}
System.out.println("Ingrese VIN:");
String vin = scanner.nextLine();
System.out.println("Ingrese marca:");
String make = scanner.nextLine();
System.out.println("Ingrese modelo:");
String model = scanner.nextLine();
System.out.println("Ingrese kilometraje (entero):");
int mileage = Integer.parseInt(scanner.nextLine());
if (type.equals("sedan")) {
cars[i] = new Sedan(vin, make, model, mileage);
} else if (type.equals("utility")) {
System.out.println("¿Tiene tracción en las cuatro ruedas? (true/false):");
boolean fourWheelDrive = Boolean.parseBoolean(scanner.nextLine());
cars[i] = new UtilityVehicle(vin, make, model, mileage, fourWheelDrive);
} else { // type.equals("truck")
System.out.println("Ingrese capacidad de remolque (decimal):");
double towingCapacity = Double.parseDouble(scanner.nextLine());
cars[i] = new Truck(vin, make, model, mileage, towingCapacity);
}
}
System.out.println("\nInventario de autos:");
for (Car car : cars) {
System.out.println(car.getInfo());
}
scanner.close();
}
}