⌛⌛ Student register¶
A class testing your code and an example test input file is available for the exercise student_template_project
repository in the directory Round4/studentregister
.
Place your code into files named Student.java, Course.java, Attainment.java and
StudentRegister.java. For submitting the solution the files must be under /Round4/studentregister/
.
Implement classes Student
, Course
, Attainment
and StudentRegister
for maintaining
student data. The public functionality of the classes is described below. You are free to implement
internal (private) details as you wish.
Student
Stores the name and student number of a student.
Public constructors and member functions:
Constructor
Student(String name, String studentNumber)
: initalizes theStudent
object with the name and student number received as parameters.Member functions
getName()
andgetStudentNumber()
: return the name and student number, respectively, asString
.
Course
Stores the code, name and credits of a course.
Public constructors and member functions:
Contructor
Course((String code, String name, int credits)
: initalizes theCourse
object with the code, name and credits received as parameters.Member functions
getCode()
,getName()
jagetCredits()
: return the code, name and credits of the course, respectively. The first two asString
and the last asint
.
Attainment
Describes a course attainment as a combination of course code, student number and grade.
Public constructors and member functions:
Constructor
Attainment(String courseCode, String studentNumber, int grade)
: initializes theAttainment
object with the course code, student number and grade received as parameters.Member functions
getCourseCode()
,getStudentNumber()
andgetGrade()
: return the attainment’s course code, student number and grade, respectively. The first two asString
and the last asint
.
StudentRegister
Implements a simple student register that maintains information about students, courses and course attainments.
Public constructors and member functions:
Constructor
StudentRegister()
: initializes an emptyStudentRegister
object that does not yet contain information about students, courses or attainments.Member function
getStudents()
: returns anArrayList<Student>
list of all students currently stored in the register. The students are in alphabetical order of their names.Member function
getCourses()
: returns anArrayList<course>
list of all courses currently stored in the register. The courses are in alphabetical order of their names.Member function
addStudent(Student student)
: addsstudent
into the register.Member function
addCourse(Course course)
: addscourse
into the register.Member function
addAttainment(Attainment att)
: addsattainment
into the register.Member function
printStudentAttainments(String studentNumber, String order)
: prints all registered course attainments of the specified student to standard output. The second parameterorder
specifies in which order the attainments should be printed.If the register does not contain a student whose student number is
studentNumber
, print a message of form “Unknown student number: studentNumber
”.First print a header line of form “
studentName (studentNumber):
”.After the header line, print each attainment in the form “`` courseCode courseName: grade``”. note the two spaces in the beginning.
If
order
is “by name”, the attainments are printed in alphabetical order of course
names.
If
order
is “by code”, the attainments are printed in alphabetical order of course codes.Otherwise the attainments are printed in the order they were stored into the register. E.g. first the attainment that was stored the earliest, and last the attainment that was stored the latest.
Member function
printStudentAttainments(String studentNumber)
: prints all registered course attainments of the specified student to standard output in the order they were stored into the register. The only difference between this function and the precedingprintStudentAttainments
function is the missingorder
parameter.
Testing the implementation¶
You may test your class implementations by using the test program given in the file
StudentRegisterTest.java
, the example data in the files students.txt
, courses.txt
and attainments.txt
, and the example output in the file output.txt
. Place these files and
your own classes into the same directory, compile the program e.g. as javac *.java
, and run the
test as java StudentRegisterTest students.txt courses.txt attainments.txt
. The program output
should be identical with the example output given in the file output.txt
.
A+ presents the exercise submission form here.