-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnrolmentStandard.java
More file actions
63 lines (56 loc) · 2.04 KB
/
EnrolmentStandard.java
File metadata and controls
63 lines (56 loc) · 2.04 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
import java.util.Scanner;
/*
* This code ask for your name and validates it
* Then it ask for the year you were born and also valodates it
* Then it ask for your GCSE Maths score and validates it
* Finally all data is outputed
*/
public class EnrolmentStandard{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
while(name.isEmpty() || name.length() <= 1){
System.out.print("Name can't be empty. Enter your name: ");
name = scanner.nextLine();
}
System.out.print("Enter the year you were born: ");
String yearTemp = scanner.nextLine();
int year;
try{
year = Integer.parseInt(yearTemp);
}catch(Exception exeption){
year = -1;
}
while(year < 0){
System.out.print("Year can't be less than 0. Enter the year you were born: ");
yearTemp = scanner.nextLine();
try{
year = Integer.parseInt(yearTemp);
}catch(Exception exeption){
year = -1;
}
}
System.out.print("Enter your math GCSE score: ");
String mathGcseTemp = scanner.nextLine();
int mathGcse;
try{
mathGcse = Integer.parseInt(mathGcseTemp);
}catch(Exception exeption){
mathGcse = -1;
}
while(mathGcse < 1 || mathGcse > 9){
System.out.print("Score can't be lower than 1 or greater than 9. Enter your math GCSE score: ");
mathGcseTemp = scanner.nextLine();
try{
mathGcse = Integer.parseInt(mathGcseTemp);
}catch(Exception exeption){
mathGcse = -1;
}
}
scanner.close();
System.out.println("Name: " + name);
System.out.println("Year born: " + year);
System.out.println("Math GCSE: " + mathGcse);
}
}