Suggestions

  • As the first step, you construct the GUI but not implement functions for button clicks.
  • For the give function buttons, you may start to implement the exit function first, and then the functions of Add and Delete buttons.
  • Always keep a copy of your working code before you cover more requirements.
  • Don’t work on the extra credit questions unless you complete all the basic part.

Case

The CIS department needs a GUI application to make course assignments to its instructors. With this application, the department can also add new instructors and new courses. After an instructor leaves the department or a course is terminated, the corresponding record can be removed. Basic business rules are as follows.

  • An instructor can be assigned to no more than three classes. (CIS 101-1 and CIS 101-2 are considered two different classes.)
  • The same class, such as CIS 101-1, cannot be assigned twice if it has been assigned to someone already.

Requirements in Summary

  • Develop a Java GUI application (similar to the one shown in Fig. 1). Besides, it reads instructor and course information from two provided text files (instructor.txt and course.txt) and shows the contents in two JList
  • Quit the application with the Exit button
  • Add a new instructor or a new course (to the department)
  • Delete unneeded instructor or course(s)
  • Assign an instructor to up to three courses
  • Display all current assignments for selected instructor or for selected course(s). See image.

Requirements in Details

Three text files. Once the program starts, it reads all instructor’s records from instructor.txt (each row in the file is one record and is in the format of instructorID<>instructorName, where <> is the partition/delimiter between the two fields. The same delimiter is used in all three text files). It then displays instructor names in the left JList of Fig. 1. The instructorList allows single selection. The course information (shown in the right JList in Fig. 1) is retrieved from course.txt which consists of courseID and courseNumber. The courseList allows multiple interval selections. The third text file, assignment.txt, contains the current course assignment records (courseID<>instructorID) to represent courses and their assigned instructors. One row represents one course assignment. The three text files are provided and already contain data. You can delete or add records in those files using your GUI application. See the following function descriptions for the five buttons.

Exit. Clicking this button to close the frame and exit the program. Instead of using mouse to click the button, pressing Alt + x will also trigger the Exit button. Refer Java API and use setMnemonic() method for this feature.

Add Record. Clicking the Add Record button will popup a window as shown in Fig. 2 asking you to select adding Instructor or adding Course. In this project, you will use showMessageDialog and showOptionDialog and metods of JOptionPane in interactions. See image.

If you clicking the Instructor button in Fig. 2, the above popup window will be closed and another popup window (Fig. 3) will allow you to enter a name for the new instructor. See image.

Clicking OK button in Fig. 3 after entering a name will add the new instructor into the instructorList in Fig. 1 and also into the instructor.txt file. Before the instructor is added into the file, an instructor id is automatically generated, and then the id and the name are inserted to the file with <> as the partition between them. The automatic generated instructor id is the number one greater than the maximum number of currently existed instructor id. Do not hard code the new ID value. Make sure your newly inserted record is in a new row.

If everything goes right, a new popup window (see Fig. 4) notifies you that new instructor record has been successfully added. Then instructorList on the GUI is also updated (see Fig. 5). See image. See figure 5 image.

If you clicking Cancel in Fig. 3, you will not add the new instructor to GUI nor update the instructor.txt file. If the instructor name already exists, you won’t add the name into the instructorList nor update the file, and you need to use a popup window (Fig. 6) to notify you that the record is not added. See image.

Instead of using mouse to click the button, pressing Alt + a will also trigger the Add button. Similarly, the Add button can also add a new course to both the course.txt and the courseList of the GUI.

Delete Record. Clicking the Delete Record button will pop a window (Fig. 7) asking you to select Instructor or Course to delete. See image.

If you clicking the Instructor button in Fig. 7, this popup window will be closed and the selected instructor in the instructorList will be deleted from the JList and also from instructor.txt. In addition, the selected instructor’s assignment records will also be removed from the assignment.txt because the instructor is removed. If no instructor in the instructorList was selected when you try to delete instructor, a warning message is shown in a popup window (Fig. 8). The program will not be terminated because of this operation/warning. See image.

If you clicking Course button on Fig. 7, this popup window will be closed and selected course(s) in the courseList will be deleted from the JList of GUI and also from the course.txt file. In addition, all course assignment records related to the course(s) will also be removed from the assignment.txt file because the course(s) is removed. If no course in the courseList was selected when you try to delete course, a warning message is shown in a popup window, similar to Fig. 8. The program will not be terminated because of this warning. Instead of using mouse to click the button, pressing Alt + d will also trigger the Delete button.

Assign to. After selecting one instructor from the instructorList and selecting up to three courses from the courseList, you click the Assign to button to assign the selected instructor to the selected course(s). A popup window informs you about the course assignments. Fig. 9 is an example if everything is right during the course assignment. See image.

To record the task assignments, your program needs to write the assignments to the existing assignment.txt in the format same as the file uses, which is courseID <>instructorID. Make sure each assignment record is in an individual line. If you try to assign a course which is already assigned, you receive a warning message as shown in Fig. 10. See image.

If you try to assign course(s) to an instructor such that the new assignment(s) will make the instructor to teach more than three courses, you will receive a warning message as shown in Fig. 11. See image.

When clicking the Assign button without selecting an instructor or at least one course, you should receive a warning message displayed in a popup window, similar to Fig. 12 and Fig. 13. See image. See figure 13 image.

Instead of using mouse to click the button, pressing Alt + s will also trigger the Assign button.

View Assignments. After you clicking the View Assignments button, the program asks you whether you want to view course assignments according to the selected instructor or the selected course(s), see Fig. 14 below. See image.

If you clicking the instructor button in Fig. 14, Fig. 14 will be closed and the current assignments for the selected instructor will display under the label “Current Assignments”. As an example, Fig. 15 shows current assignments for Cathy Harris. See image.

If you clicking the course button in Fig. 14, your program lists instructor(s) assigned to selected course(s), as shown in Fig. 16. See image.

Instead of using mouse to click the button, pressing Alt + v will also trigger the View Assignments button.

Added Features. show number of classes currently assigned next to each instructor’s name in instructorList. if a course has been assigned to someone, be able to differentiate this course in courseList, such as adding * before courseNumber.

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.