This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Lab.java
132 lines (120 loc) · 2.97 KB
/
Lab.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package ir.ac.aut;
public class Lab {
//array of students
private Student[] students;
//avg of the grades of the students in this lab
private int avg;
//string day
private String day;
//capacity of this lab
private int capacity;
//unt currentSize
private int currentSize;
//constructor
public Lab(int cap, String d) {
capacity=cap;
day=d;
students=new Student[capacity];
}
/**
*method for enrollin the students
* @param std
*/
public void enrollStudent(Student std) {
if (currentSize < capacity) {
students[currentSize] = std;
currentSize++;
} else {
System.out.println("Lab is full!!!");
}
}
/**
* method for printing info about the studnets in the class and
* the avg of the lab
*/
public void print() {
calculateAvg();
System.out.printf("The avg of the class is %d\n", avg);
for(int i=0; i<currentSize; i++){
students[i].print();
}
}
/**
* method of kind getter
* @return students
*/
public Student[] getStudents() {
return students;
}
/**
* method of kind setter
* @param students
*/
public void setStudents(Student[] students) {
this.students=students;
currentSize=students.length;
}
/**
* getter method
* @return avg of the class
*/
public int getAvg() {
return avg;
}
/**
* method for calculating (updating the avg)
*/
public void calculateAvg() {
int sum=0;
for(int i=0; i<currentSize; i++){
sum+=students[i].getGrade();
}
sum/=currentSize;
avg=sum;
return;
}
/**
* getter method
* @return day
*/
public String getDay() {
return day;
}
/**
* setter method
* @param day
*/
public void setDay(String day) {
this.day=day;
return;
}
/**
* getterv method for the capacity field
* @return capacity
*/
public int getCapacity() {
return capacity;
}
/**
*setter method for the capacity field(we have to check if the value passed
* its ok)
* @param capacity
* */
public void setCapacity(int capacity) {
if(this.capacity<capacity){
System.out.printf("cannot change the capacity since some data may be lost\n");
return;
} else if(this.capacity==capacity){
return;
} else{
this.capacity=capacity;
Student newStudents [];
newStudents= new Student[capacity];
for(int i=0; i<currentSize; i++){
newStudents[i]=students[i];
}
students=newStudents;
return;
}
}
}