This course has already ended.

⌛⌛ 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 the Student object with the name and student number received as parameters.

      • Member functions getName() and getStudentNumber(): return the name and student number, respectively, as String.

  • Course

    • Stores the code, name and credits of a course.

    • Public constructors and member functions:

      • Contructor Course((String code, String name, int credits): initalizes the Course object with the code, name and credits received as parameters.

      • Member functions getCode(), getName() ja getCredits(): return the code, name and credits of the course, respectively. The first two as String and the last as int.

  • 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 the Attainment object with the course code, student number and grade received as parameters.

      • Member functions getCourseCode(), getStudentNumber() and getGrade(): return the attainment’s course code, student number and grade, respectively. The first two as String and the last as int.

  • StudentRegister

    • Implements a simple student register that maintains information about students, courses and course attainments.

    • Public constructors and member functions:

      • Constructor StudentRegister(): initializes an empty StudentRegister object that does not yet contain information about students, courses or attainments.

      • Member function getStudents(): returns an ArrayList<Student> list of all students currently stored in the register. The students are in alphabetical order of their names.

      • Member function getCourses(): returns an ArrayList<course> list of all courses currently stored in the register. The courses are in alphabetical order of their names.

      • Member function addStudent(Student student): adds student into the register.

      • Member function addCourse(Course course): adds course into the register.

      • Member function addAttainment(Attainment att): adds attainment into the register.

      • Member function printStudentAttainments(String studentNumber, String order): prints all registered course attainments of the specified student to standard output. The second parameter order 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. Note that the alphabetical order is case sensitive. The sorting should use a lexicographical i.e. dictionary order where upper case letters come before lower case letters.

          • 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 preceding printStudentAttainments function is the missing order 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.

Posting submission...