-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
87 lines (77 loc) · 1.47 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
78
79
80
81
82
83
84
85
86
87
/**
* Reading exercise for 2/1/2016
*
* @author An
*
*/
public class Student {
private String firstName;
private String lastName;
private int id;
private int age;
/**
*
* @param firstName, non empty string
* @param lastName, non empty string
* @param id non-negative integer
* @param age non-negative integer
* @return nothing
*/
public Student(String firstName, String lastName, int id, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.age = age;
}
/**
*
* @param firstName,
* a non empty string
* @param lastName,
* a non empty string
*/
public void setName(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
/**
*
* @return First and last name of student in format "<first> <last>"
*/
public String getName() {
return (this.firstName + this.lastName);
}
/**
*
* @param id, non-negative integer
*/
public void setId(int id) {
this.id = id;
}
/**
*
* @return id, non-negative integer
*/
public int getID() {
return this.id;
}
/**
*
* @param age, non-negative integer
* @throw IllegalArgumentException if an integer value less than 1 is given
*/
public void setAge(int age) {
if (age > 0) {
this.age = age;
} else {
throw new IllegalArgumentException();
}
}
/**
*
* @return age of student, a non-negative, non-zero integer
*/
public int getAge() {
return this.age;
}
}