⌛⌛ Student register¶
Of the submission problem
Plussa should now accept submissions for this task.
A class for testing your code and example test input and output files are
available for the exercise in the remote material repository. The files are in
the round4/studentregister
directory.
Place your code into files named Student.java, Course.java, Attainment.java and
StudentRegister.java. These file must be in the /round4/studentregister/
directory.
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 the screen. 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"
. Please, note the two spaces in the beginning.If
order
is"by name"
, the attainments are printed in the alphabetical order of course names. Use thecompareTo
function from theString
class as the comparison function for sorting. Since the order established bycompareTo
is case sensitive, the upper case letters come before the lower case letters. You do not need to worry now about the case-sensitivity in sorting. It is just something you should now as a programmer.If
order
is"by code"
, the attainments are printed in the alphabetical order of course codes. Apply thecompareTo
function of theString
class also here as a comparison function.Otherwise the attainments are printed in the order they were stored into the register: The 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 the screen in the order they were stored into the register. The only difference between this function and the precedingprintStudentAttainments
function is the missingorder
parameter.Please, examine the output file given in the supplementary material for details of printing.
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, for example, 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
.
Submitting¶
Make sure before submission that your classes are in the /round4/studentregister/
directory and that you have pushed the latest changes to your personal remote
repository. When ready, enter the URL of your personal remote directory in the field
below. The URL is https://course-gitlab.tuni.fi/compcs140-spring2023/------
,
where ------
denotes your Tampere university username.
A+ presents the exercise submission form here.