Created
August 16, 2016 17:30
-
-
Save YanchevskayaAnna/bb09f28ff85d85c9b9b1896d2a868a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Level_2.week_1.university; | |
/** | |
* Created by pc on 09.08.2016. | |
*/ | |
public class Student { | |
private Subject[] subjectList; | |
private String name; | |
private Address address; | |
private int subjectQuantity; | |
private static final int SIZE = 10; | |
public Student(String name, Address address) { | |
this.name = name; | |
this.address = address; | |
subjectList = new Subject[SIZE]; | |
} | |
public String toString(){ | |
return String.format("name : %s, address : %s", name, address.toString()); | |
} | |
public String getName() { | |
return name; | |
} | |
public Address getAddress() { | |
return address; | |
} | |
public Subject[] getSubject() { | |
return subjectList; | |
} | |
public void learning(Subject subject){ | |
int hours = (int) subject.getSemesterHours().getHours(); | |
subject.setStudentHours(hours); | |
subject.setStudentValue(subject.generateStudentValue()); | |
} | |
public boolean addSubject(Subject subject){ | |
subjectList[subjectQuantity++] = subject; //todo can not be a free place | |
return true; | |
} | |
public boolean removeLastSubject(){ | |
subjectList[subjectQuantity--] = null; | |
return true; | |
} | |
public String showAllInfoAboutSubjects(){ | |
StringBuilder st = new StringBuilder(); | |
for (int i = 0; i < subjectQuantity; i++) { | |
st.append(i + "| " + subjectList[i].toString() + "\n"); | |
} | |
return st.toString(); | |
} | |
public double getGPA(){ | |
if (subjectQuantity == 0) { | |
System.out.println("not available subject"); | |
return -1; //todo return 0; add test fot this method; | |
} | |
double gpa = 0; | |
for (int i = 0; i < subjectQuantity - 1; i++) { | |
gpa += subjectList[i].getStudentValue(); | |
} | |
return gpa / subjectQuantity; | |
} | |
public void expandSubjectList(){ | |
if (subjectQuantity >= subjectList.length){ | |
Subject[] newStudentList = new Subject[subjectList.length * 2]; | |
System.arraycopy(subjectList, 0, newStudentList, 0, subjectList.length); | |
subjectList = newStudentList;; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment