-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPractica03.java
More file actions
76 lines (56 loc) · 1.67 KB
/
Practica03.java
File metadata and controls
76 lines (56 loc) · 1.67 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
package Practica;
import java.util.Scanner;
class Auto {
private String color;
private String marca;
private int anio;
private String traccion;
public Auto(String color, String marca, int anio, String traccion) {
this.color = color;
this.marca = marca;
this.anio = anio;
this.traccion = traccion;
}
public String toString() {
// String mensaje = String.format("Color: %s\nMarca: %s\nAño: %d\nTracción: %s",
// color, marca, anio, traccion);
return "--------------------------\nColor: " + color + "\nMarca: " + marca + "\nAño: " + anio + "\nTracción: "
+ traccion;
}
}
class Garage {
Scanner teclado = new Scanner(System.in);
Auto[] estacionamiento = new Auto[3];
Garage(Scanner teclado) {
this.teclado = teclado;
}
public void agregarAuto(int lugar) {
System.out.println("ingrese el Color");
String color = teclado.nextLine();
System.out.println("ingrese la Marca");
String marca = teclado.nextLine();
System.out.println("ingrese el Año");
int anio = teclado.nextInt();
teclado.nextLine(); // Limpiar el buffer
System.out.println("ingrese la Tracción");
String traccion = teclado.nextLine();
Auto auto = new Auto(color, marca, anio, traccion);
this.estacionamiento[lugar] = auto;
}
public void listarAutos() {
for (Auto auto : estacionamiento) {
if (auto != null) {
System.out.println(auto.toString());
}
}
}
}
class Practica03 {
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
Garage garage = new Garage(teclado);
garage.agregarAuto(0);
garage.listarAutos();
teclado.close();
}
}