⌛⌛ Student register

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.

The exercise is returned as a Maven project. Place the pom.xml file in the round4/studentregister directory of your local repository and create to this directory the src/main/java subdirectory. Create class files Student.java, Course.java, Attainment.java and StudentRegister.java and attach them to the fi.tuni.prog3.studentregister package. Your files should be in the round4/studentregister/src/main/java/fi/tuni/prog3/studentregister directory. NetBeans creates the directory structure matching the package for this task automatically, provided that you enter correct values, when creating your Maven project.

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() and 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 the screen. 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". 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 the compareTo function from the String class as the comparison function for sorting. Since the order established by compareTo 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 worth knowing about how many programming languages work.

          • If order is "by code", the attainments are printed in the alphabetical order of course codes. Use the compareTo function of the String class also here as a comparison function.

          • Otherwise the attainments are printed in the order they were stored into the register: The first attainment that was stored the earliest and the last 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 preceding printStudentAttainments function is the missing order parameter.

      • Please examine the output file given in the supplementary material for details of printing.

The automatic tests, and the ones given below, assume that you make the following definitions in your pom.xml project file:

  • The value of artifactId is studentregister.

  • The value of version is 1.0.

  • The values of the maven.compiler.source and maven.compiler.target elements are 17 or lower. The grader uses Java 17, so any newer versions won’t work.

  • A Onejar plugin definition where the value of mainClass is StudentRegisterTest which is the name of the given test class (see below).

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.

Set StudentRegisterTest.java into the root of the src/main/java subdirectory of your Maven project, and the other files into the root directory of your Maven project, that is, where the pom.xml is. Note that StudentRegisterTest.java does not include a package definition and therefore is not placed into a deeper subdirectory.

After this you can compile the program with mvn package and run the test as java -jar target/studentregister-1.0.one-jar.jar students.txt courses.txt attainments.txt in the root directory of the project. The test should produce the output depicted in the file output.txt.

Submitting

Submitting is done as usual by entering the URL of your personal remote directory in the field below.

A+ presents the exercise submission form here.

Posting submission...