-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVetorUsandoClasse
80 lines (57 loc) · 1.55 KB
/
VetorUsandoClasse
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
package vetor;
import java.util.Locale;
import java.util.Scanner;
public class Programa {
public static void main(String[] args) {
Locale.setDefault(Locale.US);
Scanner sc = new Scanner(System.in);
Hospedes[] vect = new Hospedes[10];
System.out.println("Quantidade de pessoas a serem Hospedada? ");
int quantPessoas = sc.nextInt();
for(int i = 1; i<=quantPessoas;i++) {
System.out.println(i+"º"+" Hospede a ser cadastrado");
System.out.println();
System.out.println("Digite o nome do hospede: ");
sc.nextLine();
String nome = sc.nextLine();
System.out.println("Digite o email do hospede: ");
String email = sc.nextLine();
System.out.println("Digite o quarto que sera hospedado: ");
int quarto = sc.nextInt();
vect[quarto] = new Hospedes(nome, email);
}
System.out.println();
System.out.println("Quartos ocupados:");
for (int i=0; i<10; i++) {
if (vect[i] != null) {
System.out.println("Número do quarto: "+i+ vect[i]);
}
}
sc.close();
}
}
//Classe de hospedes
package vetor;
public class Hospedes {
private String nome;
private String email;
public Hospedes(String nome, String email) {
this.nome = nome;
this.email = email;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String toString() {
return ", Nome do cliente: "+getNome() +", email cadastrado: "+getEmail();
}
}