-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourse.java
102 lines (94 loc) · 2.6 KB
/
Course.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
94
95
96
97
98
99
100
101
102
import java.util.ArrayList;
public class Course {
private String name;
private String code;
private int vahed;
private int capacity;
private ArrayList<Student> students;
boolean flag = true;
public Course(String name, String code,int vahed,int capacity) {
students = new ArrayList<Student>();
this.name = name;
if (validCode(code))
this.code = code;
else System.out.println("invalid code!");
if (validVahed(vahed))
this.vahed = vahed;
else System.out.println("invalid vahed!");
if (checkCapacity(capacity))
this.capacity = capacity;
else System.out.println("out of capacity!");
}
public boolean checkCapacity(int capacity){
if (students.size() <= capacity)
return true;
else
return false;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setVahed(int vahed) {
if (validVahed(vahed))
this.vahed = vahed;
else
System.out.println("invalid index!");
}
public void setCapacity(int capacity) {
if (checkCapacity(capacity))
this.capacity = capacity;
else
System.out.println("out of capacity!");
}
public void setCode(String code) {
if (validCode(code))
this.code = code;
else
System.out.println("invalid code!");
}
public String getCode() {
return code;
}
public int getVahed() {
return vahed;
}
public boolean validCode(String code){
if (code.length() == 4)
return true;
else
return false;
}
public boolean validVahed(int vahed){
if(vahed >= 1 && vahed <= 3)
return true;
else
return false;
}
public boolean checkStudent(){
for (Student i: students){
if((i.getIdNumber()).equals(students))
flag = false;
}
return flag;
}
public void deleteStudent(Student student){
if (students.contains(student))
students.remove(student);
else
students.add(student);
}
public void addStudent(Student student){
if (checkCapacity(capacity) && validCode(code) && validVahed(vahed) && checkStudent()){
students.add(student);
}
}
public void printCourse(){
System.out.print(name + ": ");
for (Student s: students)
System.out.print(s.getName() + " ");
System.out.println();
}
}