Lab Exercise Two

Create a class list system for a school. The program must implement a single class, which is described in the following:

  • The student class must track attributes of students, including program, year, average grade in percentage and methods. Methods include constructor(s), accessors and mutators, toString, equals, and any other needed methods.
  • The program must tokenize the input of program and year using the "split" method in the String class.
  • Program and year are mandatory when entering a student information; otherwise, your program should reject the input and let the user try again. The average grade is optional with the default of 0.0%. For program and year, we assume the format of "< program> < year>" although the user can enter any number of space characters between < program> and < year>. For example, CompSci 4 and CompSci 4 are both valid.
  • Assume that all programs are one word (i.e., no white spaces such as CompSci, Psych, Math, ...)
  • The program should store all Student objects in an ArrayList.
  • The menus in the command loop should look like what is done in Lab Exercise One:
    • Enter information for a new student.
    • Show all student information with program, year, and average grade on separate lines
    • Print the average of the average grades for class and the total number of students.
    • Enter a specific program and show all student information for that program
    • End the program.

In the example below, words in italics represents user actions, while bolded words represent program output. In this example, the average grade of the given student is set to the default of 0%.

Example Usage and output:

-------------------------------------------------------------
Program displays menu.

User selects option (1)

Enter Student Program and Year:
CompSci 4

Enter Average grade, or leave blank:
User presses enter (meaning assumed 0)

Program displays menu.
-------------------------------------------------------------

Note that for option (2), output should resemble the following:

Program: CompSci
Year: 4
Average Grade: 0.0

Lab 3

Extend the class list system you created in Lab Exercise 2 with a subclass and also allow file I/ O for user interactions. The original program and its functionality should remain, but several new menu options are to be added:

  • The Student class will now have a subclass GraduateStudent, which inherits all attributes and methods from the original Student class.
  • However, all GraduateStudents should have three new variables: supervisor, isPhD (boolean), and undergraduateSchool, where supervisor and isPhD are mandatory.
  • The toString method for Student should show the attributes: program, year, and average grade on separate lines.
  • The toString method for GraduateStudent should override that for Student, which will not only print program, year, and average grade, but also add additional lines for PhD/ Masters, supervisor, and undergraduateSchool, where the decision to print "PhD" or Masters is determined by the value of isPhD.
  • The menu should now look like the following:
    • Enter information for a new Student.
    • Enter information for a new GraduateStudent
    • Show all student information with each attribute on a separate line
    • Print the average of the average grades for all students as well as the total number of students
    • Enter a specific program and show all student information for that program
    • Load student information from an input file.
    • Save all student information to an output file
    • End program.

Note (1): In the class list system, all students and graduate students should be stored in a single ArrayList, and Option (3) essentially loops through the list by calling the toString method for each object (either a student or a graduate student).

Note (2): A filename needs to be provided for Options (6) and (7). Loading an input file will create the related student objects and add them to the existing ArrayList, while saving an output file will dump the exisiting ArrayList to the related file. If an input file is empty, a warning message should be given to the user and writing output to an existing file will wipe out its current content.

Note (3): For graduate students, year is how many years they have been working on their graduate degrees.

In the example below, words in italics represents user actions, while bolded words represent program output. In this example, the average grade of the given student is set to the default of 0%.

Example Usage and output:

Program displays menu.
User selects option (6).

Please enter the name of the input file:
students.txt

***Reads and parses file***

Program displays menu.
-------------------------------------------------------------

The input file should be a text file with the following format:

Program Year avgGrade supervisor isPhD undergraduateSchool

where program, supervisor, and undergraduateSchool are all made of single words and isPhD is either 1 or 0

Examples:

CompSci 4 85.4 Song 1 Guelph
Psych 2 92.1
Biology 1 75.0 Cornell 0 McGill

You can assume that the input file is perfectly formatted since it is likely saved previously by your program. However, you cannot assume that the input file will exist, which must be error checked.

Lab 4

Extend the student class system you created in Lab Exercise Three with a HashMap and ensure that the program is robust by implementing proper exception handling. Finally, create a Graphical User Interface (GUI) for the Student Class Management System that has been developed so far in the labs.

  • Add the lastName attribute to the Student class. This should be an additional input for the user to enter since it is mandatory for each student.
  • Due to a forecasted increase in student enrolment, your program must handle the search more efficiently at a bigger scale. Instead of checking the ArrayList sequentially, we can create a HashMap index for all Students so that the search can be done more efficiently. To create a HashMap, we need to associate each Student with a unique keyvalue, which consists of the program, the year, and the last name, all of which are concatenated into one string and normalized into lower cases.
  • Exceptions are to be thrown in the constructor(s) of the Student class and caught in a method that calls these constructors. Please refer to the example in the lab slides for more information. To create a valid Student object, we should always provide the program, year, and last name. In addition, if other information is available, an average grade should be between 0 and 100 (inclusive). Any violations to these conditions should throw an exception in the related constructor(s).
  • Every time we get the Student information from the user or from the input file, we should always check if the corresponding key value is already on the HashMap. If so, simply display a warning message and reject the input. Otherwise, create a Student object and add it to both the ArrayList and the HashMap. In other words, the HashMap is not only useful to speed up the search but also helpful for the duplicate check of the key values.
  • The menu should now look like the following:
    • Enter information for a new Student.
    • Enter information for a new GraduateStudent
    • Show all student information with each attribute on a separate line
    • Print the average of the average grades for all students as well as the total number of students
    • Enter a specific program and show all student information for that program
    • Load student information from an input file.
    • Save all student information to an output file
    • Lookup via HashMap with program, year, and lastName.
    • End Program

Example Usage and output:

Program displays menu.
User selects option (6).
Please enter the name of the input file:
students.txt
***Reads and parses file***
Program displays menu.
-------------------------------------------------------------

The input file should be a text file with the following format:

Program Year avgGrade supervisor isPhD undergraduateSchool lastName

where program, supervisor, undergraduateSchool, and lastName are all made of single words and isPhD is either 1 or 0

Examples:

CompSci 4 85.4 Song 1 Guelph Smith
Psych 2 92.1 Brown
Biology 1 75.0 Wineberg 0 McGill MacDonald

You can assume that the input file is perfectly formatted since it is likely saved previously by your program. However, you cannot assume that the input file will exist, which must be error checked.

Information for the GUI part of the assignment:

  • The GUI should be implemented using the Swing and AWT packages directly, not any other GUI building tools.
  • ALL functionality and implementation (code) from previous lab exercises will be needed for this lab exercise.
  • Options available to the user are:
Enter info about a new Student
Enter info about a new GraduateStudent
Print out all student info.
Print average of student averages, as well as total number of students.
Read input file.
File Data output.
Lookup via a HashMap key.
End program.

While no interface is specified, two are suggested in the following. Two rows of buttons across the top quarter of the interface might represent the options above. The next quarter of the interface might be a text input area used for searches and inputting file names. Finally, the bottom half of the interface would be reserved for a large, scrollable text area where all output is presented.

Alternatively, the interface can be divided into a small left panel and a large right panel. At the bottom part of the left panel, we can place all the buttons for the options and the top part for the input information such as searches and input file names. The large right panel is reserved for the scrollable text area that displays all output information.

Note that these interface ideas are only suggestions and you are allowed to create your own designs as long as all the functionality is supported. For example, you could also organize all the options into multiple menus in a menu bar so that you can free up more space for inputting data and displaying output information.

The rubric for this lab assignment is intentionally vague. It is up to you to design a clean interface for the user to work with. Usability is part of the marking scheme, and as long your UI is intuitive you can achieve a maximum of 100% for this lab exercise.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.