-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
77 lines (72 loc) · 1.58 KB
/
Student.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
package realcode;
import java.util.Scanner;
public class Student {
String name;
String sex;
int age;
String stuNo;
public void inputInformation() {
Scanner reader = new Scanner(System.in);
a:for(;;) {
try {
System.out.println("请输入姓名");
name=reader.nextLine();
System.out.println("录入成功~");
break a;
}
catch(Exception e) {
System.out.println("您输入的 “"+name+"” 格式不正确,请重新输入!");
}
}
b:for(;;) {
try{
System.out.println("请输入性别(中文)");
sex=reader.nextLine();
sexJudge(sex);
break b;
}
catch(JudgeException e) {
System.out.println(e.JudgeException(sex));
}
}
c:for(;;) {
try{
System.out.println("请输入年龄(15-75岁)");
age=reader.nextInt();
ageJudge(age);
break c;
}
catch(JudgeException e) {
System.out.println(e.JudgeException(age));
}
}
d:for(;;) {
try {
Scanner reader0 = new Scanner(System.in);
System.out.println("请输入学号");
stuNo=reader0.nextLine();
System.out.println("录入成功~");
break d;
}
catch(Exception e) {
System.out.println("您输入的“"+stuNo+"”格式不正确,请重新输入!");
}
}
}
public void sexJudge(String sex) throws JudgeException{
String x="男";
String y="女";
if (sex.equals(x)||sex.equals(y)){
System.out.println("录入成功~");
}
else throw new JudgeException();
}
public void ageJudge(int age) throws JudgeException{
int x=15;
int y=75;
if (age>=x&&age<=y){
System.out.println("录入成功~");
}
else throw new JudgeException();
}
}