-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntrySystemApp.java
More file actions
69 lines (57 loc) · 2.02 KB
/
Copy pathEntrySystemApp.java
File metadata and controls
69 lines (57 loc) · 2.02 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
package mini_apps;
/**
* Checks Age and ticket type given by user and determent if they enter and if yes to which type Regular ( ticket type 1 or VIP ticket type 2)
* age >= 18
* @author Giannis
* @vesion 1.0.1
*/
import java.util.Scanner;
public class EntrySystemApp {
private static final int VIP = 2;
private static final int AGE = 18;
private static final int MAX_RETRIES = 3;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int age = 0;
int type = 0;
// Validation outer loop
while (true) {
System.out.print("Give your age: ");
age = scanner.nextInt();
if (age <= 0) {
System.out.println("Your age can't be negative or zero...");
continue;
}
// Retries to enter correct ticket type loop
int retries = MAX_RETRIES;
while (retries > 0) {
System.out.print("Give your type of ticket: ");
type = scanner.nextInt();
if (type != 1 && type != 2) {
retries--;
System.out.println("Your ticket type can only be 1 ( Regular ) OR 2 (VIP)");
System.out.println("You have " + retries + " tries before information reset");
} else break;
}
if (retries == 0) {
System.out.println("Information reset please re - enter it");
continue;
}
break; // End outer loop
}
// Entry check
if (age < AGE) {
System.out.print("Access Denied");
} else {
if (age >= 100) {
System.out.println("How the hell are you still alive ?!"); // Easter egg
}
if (type != VIP) {
System.out.print("Regular access granted - but not VIP");
} else {
System.out.print("Welcome Sir");
}
}
scanner.close();
}
}