Commit c07c04d8 authored by 9831045's avatar 9831045

added extra testings

parent 2c6b6869
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="721d25be-807f-4a41-a78a-d223bc93b2f4" name="Default Changelist" comment=""> <list default="true" id="721d25be-807f-4a41-a78a-d223bc93b2f4" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Run/Lab.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Run/Lab.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Run/Run.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Run/Run.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Run/Student.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Run/Student.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Lab.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Lab.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Lab.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Lab.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Run.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Run.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Run.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Run.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Student.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Student.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/Student.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Student.java" afterDir="false" />
...@@ -69,22 +72,22 @@ ...@@ -69,22 +72,22 @@
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state x="275" y="21" key="#Project_Structure/0.0.1366.728@0.0.1366.728" timestamp="1583492226195" /> <state x="275" y="21" key="#Project_Structure/0.0.1366.728@0.0.1366.728" timestamp="1583492226195" />
<state width="1366" height="180" key="GridCell.Tab.0.bottom" timestamp="1583500264815"> <state width="1366" height="180" key="GridCell.Tab.0.bottom" timestamp="1583501471086">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1366" height="180" key="GridCell.Tab.0.bottom/0.0.1366.728@0.0.1366.728" timestamp="1583500264815" /> <state width="1366" height="180" key="GridCell.Tab.0.bottom/0.0.1366.728@0.0.1366.728" timestamp="1583501471086" />
<state width="1366" height="180" key="GridCell.Tab.0.center" timestamp="1583500264814"> <state width="1366" height="180" key="GridCell.Tab.0.center" timestamp="1583501471086">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1366" height="180" key="GridCell.Tab.0.center/0.0.1366.728@0.0.1366.728" timestamp="1583500264814" /> <state width="1366" height="180" key="GridCell.Tab.0.center/0.0.1366.728@0.0.1366.728" timestamp="1583501471086" />
<state width="1366" height="180" key="GridCell.Tab.0.left" timestamp="1583500264814"> <state width="1366" height="180" key="GridCell.Tab.0.left" timestamp="1583501471086">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1366" height="180" key="GridCell.Tab.0.left/0.0.1366.728@0.0.1366.728" timestamp="1583500264814" /> <state width="1366" height="180" key="GridCell.Tab.0.left/0.0.1366.728@0.0.1366.728" timestamp="1583501471086" />
<state width="1366" height="180" key="GridCell.Tab.0.right" timestamp="1583500264814"> <state width="1366" height="180" key="GridCell.Tab.0.right" timestamp="1583501471086">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
<state width="1366" height="180" key="GridCell.Tab.0.right/0.0.1366.728@0.0.1366.728" timestamp="1583500264814" /> <state width="1366" height="180" key="GridCell.Tab.0.right/0.0.1366.728@0.0.1366.728" timestamp="1583501471086" />
<state x="184" y="0" key="SettingsEditor" timestamp="1583493438190"> <state x="184" y="0" key="SettingsEditor" timestamp="1583493438190">
<screen x="0" y="0" width="1366" height="728" /> <screen x="0" y="0" width="1366" height="728" />
</state> </state>
......
...@@ -25,6 +25,7 @@ public class Lab { ...@@ -25,6 +25,7 @@ public class Lab {
if (currentSize < capacity) { if (currentSize < capacity) {
students[currentSize] = std; students[currentSize] = std;
currentSize++; currentSize++;
calculateAvg();
} else { } else {
System.out.println("lab is full!!!"); System.out.println("lab is full!!!");
} }
...@@ -68,9 +69,11 @@ public class Lab { ...@@ -68,9 +69,11 @@ public class Lab {
currentSize = 0; currentSize = 0;
for (Student i : students) { for (Student i : students) {
this.students[j] = new Student(i.getFirstName(),i.getLastName(),i.getId()); this.students[j] = new Student(i.getFirstName(),i.getLastName(),i.getId());
this.students[j].setGrade(i.getGrade());
j++; j++;
currentSize++; currentSize++;
} }
calculateAvg();
} }
...@@ -88,7 +91,7 @@ public class Lab { ...@@ -88,7 +91,7 @@ public class Lab {
public void calculateAvg() { public void calculateAvg() {
int sum = 0; int sum = 0;
int i = 0; int i = 0;
for (; i < students.length; i++) { for (; i < currentSize ; i++) {
sum += students[i].getGrade(); sum += students[i].getGrade();
} }
avg = sum / i; avg = sum / i;
......
...@@ -7,10 +7,7 @@ public class Run { ...@@ -7,10 +7,7 @@ public class Run {
Student std3 = new Student("Ahmad", "Asadi", "9031054"); Student std3 = new Student("Ahmad", "Asadi", "9031054");
//creating a students array //creating a students array
Student[] students = new Student[3]; Student[] students = new Student[3];
//initializing the students in the array
students[0] = std1;
students[1] = std2;
students[2] = std3;
//running the simple functions in the AP manual //running the simple functions in the AP manual
std1.print(); std1.print();
std1.setGrade(15); std1.setGrade(15);
...@@ -23,23 +20,51 @@ public class Run { ...@@ -23,23 +20,51 @@ public class Run {
std3.print(); std3.print();
std3.setFirstName("HamidReza"); std3.setFirstName("HamidReza");
std3.print(); std3.print();
//printing an error message when the grade is invalid
std1.setGrade(21);
std2.setGrade(-1);
//no problem when the grade is fine
std1.setGrade(20);
std2.setGrade(19);
//setting the new ID
std3.setId("9034212");
//initializing the students in the array
students[0] = std1;
students[1] = std2;
students[2] = std3;
//running extra functions //running extra functions
//setting the day //setting the day
String day = new String("98/1/23"); String day = new String("98/1/23");
//setting the capacity //setting the capacity
int cap = 3; int cap = 3;
//initializing Lab constructor //initializing Lab constructor
Lab lab = new Lab(cap,day); Lab lab = new Lab(cap,day);
//setting the students //setting the students
lab.setStudents(students); lab.setStudents(students);
//calulating the average
lab.calculateAvg();
//using labs print method //using labs print method
lab.print(); lab.print();
//now lets set a new day //now lets set a new day
String newDay = new String("98/2/2"); String newDay = new String("98/2/2");
lab.setDay(newDay); lab.setDay(newDay);
System.out.println( "this is the new lab day -> " + lab.getDay()); System.out.println( "this is the new lab day -> " + lab.getDay());
//now to show that no one can attend the lab when its full
Student std4 = new Student("new students first name","new students last name ","9031059"); //now to show that no one can attend the lab when its full this will cause an error message
Student std4 = new Student("new first name","new last name ","9031059");
lab.enrollment(std4); lab.enrollment(std4);
//now lets increase the classes capacity //now lets increase the classes capacity
...@@ -47,17 +72,12 @@ public class Run { ...@@ -47,17 +72,12 @@ public class Run {
//the new lab student can be enrolled //the new lab student can be enrolled
lab.enrollment(std4); lab.enrollment(std4);
//printing the labs new list //printing the labs new list
students = lab.getStudents();
students[0].print();
students[1].print();
students[2].print();
students[3].print();
lab.print(); lab.print();
//what if we want to get the student array itself
students = lab.getStudents();
//printing the new average because we just added std4
System.out.println("The new lab average is = " + lab.getAvg());
} }
} }
......
...@@ -41,7 +41,7 @@ public class Student { ...@@ -41,7 +41,7 @@ public class Student {
* @param score represents the grade of the student * @param score represents the grade of the student
*/ */
public void setGrade(int score){ public void setGrade(int score){
if( score < 20 && score >= 0 ) { if( score <= 20 && score >= 0 ) {
grade = score; grade = score;
} }
else else
......
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