-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplicationProgram.java
93 lines (80 loc) · 2.02 KB
/
applicationProgram.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
package aplication;
import java.util.Scanner;
import entities.Rooms;
public class Programa {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Rooms[] rooms = new Rooms[10];
System.out.print("Enter how many rooms will be rented: ");
int n;
while (true) {
if (sc.hasNextInt()) {
n = sc.nextInt();
if (n > 0) {
sc.nextLine();
break;
} else {
System.out.println("Invalid data. Try again!");
System.out.print("Enter how many rooms will be rented: ");
sc.nextLine();
}
} else {
System.out.println("Invalid data. Try again!");
System.out.print("Enter how many rooms will be rented: ");
sc.nextLine();
}
}
String name, email;
int room;
for (int i = 0; i < n; i++) {
System.out.printf("Rent #%d:%n", i+1);
System.out.print("Name: ");
while (true) {
name = sc.nextLine();
if (name.matches("[a-zA-ZÀ-ÿ ]+")) {
break;
} else {
System.out.println("Invalid data. Try again!");
System.out.print("Name: ");
}
}
System.out.print("Email: ");
while (true) {
email = sc.nextLine();
if (email.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")) {
break;
} else {
System.out.println("Invalid data. Try again!");
System.out.print("Email: ");
sc.nextLine();
}
}
System.out.print("Room: ");
while (true) {
if (sc.hasNextInt()) {
room = sc.nextInt();
if (room >= 0 && room < 10) {
sc.nextLine();
break;
} else {
System.out.println("Invalid data. Try again!");
System.out.print("Room: ");
sc.nextLine();
}
} else {
System.out.println("Invalid data. Try again!");
System.out.print("Room: ");
sc.nextLine();
}
}
rooms[room] = new Rooms(name, email);
}
System.out.println("Busy rooms:");
for (int i = 0; i < 10; i++) {
if (rooms[i] != null) {
System.out.printf("%d: %s, %s%n", i, rooms[i].getnames(), rooms[i].getEmails());
}
}
sc.close();
}
}