📄 student.java
字号:
package Entities;
import Sets.*;
import dslib.list.LinkedListUos;
/** Represents a student as a specific kind of person */
public class Student extends Person
{
/** Create a student from a name and a student number */
public Student(String newName, int num, int code)
{
name = newName;
studentNum = num;
accessCode = code;
currentCourses = new LinkedListUos();
gradeList = new LinkedListUos();
}
protected int accessCode;
protected SimpleDate accessTime;
protected int studentNum;
public LinkedListUos currentCourses;
public LinkedListUos gradeList;
protected double totalPaid;
protected College college;
/** Add 'gh' to the list of grade histories */
public void recordGrade(GradeRecord gh)
{
gradeList.insert(gh);
/** set the grade in the course registration object */
currentCourses.goFirst();
while (!currentCourses.after())
{
StudentReg cur = (StudentReg)currentCourses.item();
if (cur.callNum().sameCourse(gh.callNum()))
break;
currentCourses.goForth();
}
if (currentCourses.itemExists())
((StudentReg)currentCourses.item()).setGrade(gh.grade());
}
/** Change the grade the student got for the class */
public void changeGrade(GradeRecord newGrade)
{
/** locate the grade history object if it exists */
gradeList.goFirst();
while (!gradeList.after())
{
GradeRecord cur = (GradeRecord)gradeList.item();
if (cur.sameCourse(newGrade))
break;
gradeList.goForth();
}
/** if there is a grade history object that corosponds to
to the one that needs changing, change it */
if (gradeList.itemExists())
((GradeRecord)gradeList.item()).setGrade(newGrade.grade());
/** change the grade in the registration history */
currentCourses.goFirst();
while (!currentCourses.after())
{
StudentReg cur = (StudentReg)currentCourses.item();
if (cur.callNum().sameCourse(newGrade.callNum()))
break;
currentCourses.goForth();
}
if (currentCourses.itemExists())
((StudentReg)currentCourses.item()).setGrade(newGrade.grade());
}
/** Enroll a student in a course section */
public void registerInCourse(StudentReg cr)
{
currentCourses.insert(cr);
}
public boolean isRegistered(StudentReg cr)
{
StudentReg cur = null;
currentCourses.goFirst();
while (!currentCourses.after())
{
cur = (StudentReg)currentCourses.item();
if (cur.callNum().sameCourse(cr.callNum()))
break;
currentCourses.goForth();
}
if (currentCourses.itemExists())
{
if ((cur == null) || (cur.courseReg().withdrawalDate() != null))
return false;
else
return true;
}
else
return false;
}
/** Remove a student from a course section */
public void dropCourse(CallNum secN)
{
/** find the matching registration record and change
the withdrawal date attribute */
StudentReg dropRegistration = null;
currentCourses.goFirst();
while (!currentCourses.after())
{
if (dropRegistration != null)
break;
StudentReg cur = (StudentReg)currentCourses.item();
if (cur.callNum().sameCourse(secN))
{
dropRegistration = cur;
dropRegistration.setWithdrawalDate(Clock.getDate());
}
currentCourses.goForth();
}
if (dropRegistration == null)
System.out.println("Course not found. Drop Course -- Aborting!!!");
}
/** Pay 'amount' dollars towards the fees for this student. */
public void payAmount(double amount)
{
totalPaid += amount;
}
/** Totatl amount paid */
public double totalPaid()
{
return totalPaid;
}
/** Set the students access code */
public void setAccessCode(int newCode)
{
accessCode = newCode;
}
/** Return the access code */
public int accessCode()
{
return accessCode;
}
/** Return the access time */
public SimpleDate accessTime()
{
return accessTime;
}
/** Return the student number */
public int studentNum()
{
return studentNum;
}
/** Calculate the fees for the courses in the list */
public double calculateFees()
{
double result = 0;
currentCourses.goFirst();
while (!currentCourses.after())
{
/** make sure the student hasn't dropped the course */
StudentReg cur = (StudentReg)currentCourses.item();
if (cur.courseReg().withdrawalDate() == null)
{
Department currentDept =
DepartmentSet.getDepartment(cur.callNum().deptNum());
if (currentDept != null)
{
int category = currentDept.tuitionCategory();
Double amount = (Double)FeeTable.table.obtain(new Integer(category));
result += amount.doubleValue();
}
}
currentCourses.goForth();
}
return result;
}
/** Return a string representation of the student. */
public String toString()
{
return ("\nStudent Name : " + name + "\nStudent Number : " + studentNum);
}
} /* end of Student */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -