public class Student
extends java.lang.Object
implements java.io.Serializable, java.lang.Iterable<java.lang.String>
Constructor and Description |
---|
Student(java.lang.String id,
java.lang.String name)
Create a CSE student having the given ID and
name, and an empty (fresh) record.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other)
Test the equality of students.
|
java.lang.String |
getCourseGrade(java.lang.String course)
Determine the grade of
this student
in the given course. |
java.lang.String |
getFirstCourse()
Deprecated.
As of version 4.0, replaced with
iterator()
Determine the first course in the record of
this student. |
double |
getGpa()
Determine the grade-point-average (GPA) of
this
student. |
java.lang.String |
getID()
Determine the ID of
this student. |
java.lang.String |
getName()
Determine the name of
this student. |
java.lang.String |
getNextCourse()
Deprecated.
As of version 4.0, replaced with
iterator()
Determine the next course in the record of
this student. It is assumed a prior
invocation of getFirstCourse was
made and that it produced a non-null return. In
order to browse through all courses taken, start
by invoking getFirstCourse to get the
first course number or null (if the
student has not taken any course yet). If you do
get a non-null return, keep invoking
getNextCourse to get all the other courses
in the record until a null is
returned, indicating no more courses. |
static Student |
getRandom()
Create a randomly chosen student.
|
static Student |
getRandom(boolean same)
Create a random student having a random ID, a randomly chosen
four-letter name, and a random academic record.
|
int |
hashCode()
Compute a hash code for
this student. |
java.util.Iterator<java.lang.String> |
iterator()
Determine an Iterator over the course numbers
in the record of
this student. |
boolean |
setCourseGrade(java.lang.String course,
java.lang.String grade)
Update the student's record by indicating in it
that the student has obtained the given grade in
the given course.
|
static void |
setSeed(long seed)
Change the seed of the random sequence
returned by
getRandom() . |
java.lang.String |
toString()
Return a string representation of
this
student. |
public Student(java.lang.String id, java.lang.String name)
id
- a 9-digit ID# of the studentname
- the name of the student.java.lang.RuntimeException
- if the given
ID is not a 9-digit string.public java.lang.String getID()
this
student.this
student.public java.lang.String getName()
this
student.this
student.public java.util.Iterator<java.lang.String> iterator()
this
student.
The iterator does not support the remove
operation.iterator
in interface java.lang.Iterable<java.lang.String>
@Deprecated public java.lang.String getFirstCourse()
iterator()
Determine the first course in the record of
this
student.this
student's record. If the
record is empty, null
is returned.@Deprecated public java.lang.String getNextCourse()
iterator()
Determine the next course in the record of
this
student. It is assumed a prior
invocation of getFirstCourse
was
made and that it produced a non-null return. In
order to browse through all courses taken, start
by invoking getFirstCourse
to get the
first course number or null
(if the
student has not taken any course yet). If you do
get a non-null return, keep invoking
getNextCourse
to get all the other courses
in the record until a null
is
returned, indicating no more courses.this
student's record. If no more
courses are present in the record,
null
is returned.public java.lang.String getCourseGrade(java.lang.String course)
this
student
in the given course.course
- the given 4-digit course number.this
student has
achieved in the given course. If the given course
does not appear in the student's record,
null
is returned.public boolean setCourseGrade(java.lang.String course, java.lang.String grade)
course
- the given 4-digit course number.grade
- the given 1-letter grade.true
if the record was updated
as requested and return false
otherwise.
The record will not be updated if the given course
number is not made up of exactly 4 digits or if the
given letter grade is not one of the letters (A,B,C,D,E,F)
in capital or small-case.public boolean equals(java.lang.Object other)
this
one if
it is indeed a student object with the same ID number
as this
one.equals
in class java.lang.Object
other
- a reference to the object to test equality with.true
if other
is not null
and
it points to an object that is equal (as defined above) to
this
object, and false
otherwise.public int hashCode()
this
student.hashCode
in class java.lang.Object
public double getGpa()
this
student. The GPA is computed assuming all courses
have equal weights and that A has 5 points and F
has zero.this
student.public java.lang.String toString()
this
student.toString
in class java.lang.Object
"CSE student: "
followed by the student's name.public static Student getRandom()
getRandom(false)
.public static Student getRandom(boolean same)
Student
) 40% of the times,
a computer engineering student (class CEstudent
) 20% of the times,
a software engineering student (class SEstudent
) 20% of the times,
and an information technology student (class ITstudent
)
20% of the times.
same
- a flag that determines if a new student is to be generated (if
false
) or if a reference to the last-generated
student is to be returned (if true
).
You should normally set it to false
to get a
different student per invocation.public static void setSeed(long seed)
getRandom()
. This method
is meant to be used by a test harness so
that the same sequence can be generated
for the app being tested and its
oracle.seed
- the initial seed for random
number generator.