Commit 63915424 authored by Roholla's avatar Roholla

second commit

parent d675003e
Pipeline #2057 failed with stages
File added
File added
...@@ -105,12 +105,37 @@ public class Main { ...@@ -105,12 +105,37 @@ public class Main {
} }
/**
* This class is a representation of an actual lab
* It holds some info about the lab and has some useful methods
*/
public static class Lab { public static class Lab {
/**
* array of students in the lab
*/
private Student[] students; private Student[] students;
/**
* the average of student's grades
*/
private int avg; private int avg;
/**
* the day of the week on which each lab session is held
*/
private String day; private String day;
/**
* maximum number of students
*/
private int capacity; private int capacity;
/**
* current number of students
*/
private int currentSize; private int currentSize;
/**
* constructs a new lab
* @param capacity lab's capacity
* @param day the day of the week on which each lab session is held
*/
public Lab(int capacity, String day) { public Lab(int capacity, String day) {
students = new Student[capacity]; students = new Student[capacity];
this.capacity = capacity; this.capacity = capacity;
...@@ -118,12 +143,21 @@ public class Main { ...@@ -118,12 +143,21 @@ public class Main {
currentSize = 0; currentSize = 0;
avg = 0; avg = 0;
} }
/**
* adds the new kid(student) to our lab if possible
* @param std the new kid
*/
public void enrollStudent(Student std) { public void enrollStudent(Student std) {
if (currentSize < capacity) if (currentSize < capacity)
students[currentSize++] = std; students[currentSize++] = std;
else else
System.out.println("Lab is full!!!"); System.out.println("Lab is full!!!");
} }
/**
* prints a list of the students to standard output
*/
public void print() { public void print() {
for (int i = 0; i < currentSize; i++) { for (int i = 0; i < currentSize; i++) {
System.out.print((i + 1) + ". "); System.out.print((i + 1) + ". ");
...@@ -131,31 +165,65 @@ public class Main { ...@@ -131,31 +165,65 @@ public class Main {
} }
} }
/**
* @return the students array
*/
public Student[] getStudents() { public Student[] getStudents() {
return students; return students;
} }
/**
* adds the new kids(students) to our lab one by one;
* @param students the new kids
*/
public void setStudents(Student[] students) { public void setStudents(Student[] students) {
for(Student si: students) for(Student si: students)
enrollStudent(si); enrollStudent(si);
} }
/**
* @return the average of student's grades
*/
public int getAvg() { public int getAvg() {
return avg; return avg;
} }
/**
* sets the avg field to what it should be
*/
public void calculateAvg() { public void calculateAvg() {
int sum = 0; int sum = 0;
for(int i = 0; i < currentSize; i++) for(int i = 0; i < currentSize; i++)
sum += students[i].getGrade(); sum += students[i].getGrade();
avg = sum / currentSize; avg = sum / currentSize;
} }
/**
* @return the day of the week on which each lab session is held
*/
public String getDay() { public String getDay() {
return day; return day;
} }
/**
* sets the value of day field
* @param day the new day of the week on which each lab session is held
*/
public void setDay(String day) { public void setDay(String day) {
this.day = day; this.day = day;
} }
/**
* @return the capacity of the lab
*/
public int getCapacity() { public int getCapacity() {
return capacity; return capacity;
} }
/**
* @param capacity the new capacity
*/
public void setCapacity(int capacity) { public void setCapacity(int capacity) {
this.capacity = capacity; this.capacity = capacity;
} }
......
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment