CS 300: Programming II – Spring 2023
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CS 300: Programming II – Spring 2023
P04 Exceptional Care
Overview
Our urgent care clinic is back, and is interested in making some design improvements to their patient tracking software. Importantly, they are interested in reorganizing the program to be Object-Oriented, using exceptions to communicate error states rather than error codes, and keeping a record of past patients.
The program will still maintain the patients in order of triage priority (RED, YELLOW, or GREEN), but will maintain some additional information about each patient case and record historical patient information
in a file so it isn’t lost when patient records are removed from the list.
In this second version of our Urgent Care case manager, you will need to:
● Implement a PatientRecord object, including generating a case number from their information
● Figure out where to add a new PatientRecord to the list
● Add a new PatientRecord object to the list, maintaining it as an oversize array
● Record that a patient has been seen by medical staff
● Get some summary data of the current state of the patient record list
● Write the current summary of the data and the PatientRecords of all seen patients to a file, clearing those records out of the patient list so more can be added
Grading Rubric
5 points |
Pre-assignment Quiz: accessible through Canvas until 11:59PM on 02/27. |
20 points |
Immediate Automated Tests: accessible by submission to Gradescope. You will receive feedback from these tests before the submission deadline and may make changes to your code in order to pass these tests. Passing all immediate automated tests does not guarantee full credit for the assignment. |
15 points |
Additional Automated Tests: these will also run on submission to Gradescope, but you will not receive feedback from these tests until after the submission deadline. |
10 points |
Manual Grading Feedback: TAs or graders will manually review your code, focusing on algorithms, use of programming constructs, and style/readability. |
Learning Objectives
After completing this assignment, you should be able to:
● Implement a simple object with basic accessor and mutator methods
● Explain the different requirements of using a static vs. a non-static method
● Verify the correctness of a method which uses exceptions by designing and implementing a tester method which includes exception handling
Additional Assignment Requirements and Notes
Keep in mind:
● Pair programming is ALLOWED for this assignment. If you choose to work with a partner, you must review the partnership guidelines and declare your partnership before 11:59 PM on Sunday 02/06 using this form .
● The ONLY external libraries you may use in any of your classes are: java.io.File
java.io.PrintWriter
java.io.IOException
Use of any other packages (outside of java.lang) is NOT permitted.
● You are allowed to define any local variables you may need to implement the methods in this specification (inside methods). You are NOT allowed to define any additional instance or static variables or constants beyond those specified in the write-up.
● Only the ExceptionalCareAdmissionsTester class may contain a main method.
● All classes and methods must have their own Javadoc-style method header comments in accordance with the CS 300 Course Style Guide .
● Any source code provided in this specification may be included verbatim in your program without attribution.
● Run your program locally before you submit to Gradescope. If it doesn’t work on your computer, it will not work on Gradescope.
Need More Help?
Check out the resources available to CS 300 students here:
CS 300 Assignment Requirements
You are responsible for following the requirements listed on both of these pages on all CS 300 assignments, whether you’ve read them recently or not. Take a moment to review them if it’s been a while:
● Academic Conduct Expectations and Advice, which addresses such questions as:
○ How much can you talk to your classmates?
○ How much can you look up on the internet?
○ What do I do about hardware problems?
○ and more!
● Course Style Guide, which addresses such questions as:
○ What should my source code look like?
○ How much should I comment?
○ and more!
Getting Started
1. Create a new project in Eclipse, called something like P04 Exceptional Care.
a. Ensure this project uses Java 17. Select “JavaSE-17” under “Use an execution environment JRE” in the New Java Project dialog box.
b. Do not create a project-specific package; use the default package.
2. Download (1) Java source file from the assignment page on Canvas:
a. ExceptionalCareAdmissionsTester.java (includes a main method)
3. Create two (2) Java source files within that project’s src folder:
a. PatientRecord.java (does NOT include a main method)
b. ExceptionalCareAdmissions.java (does NOT include a main method)
⭐We strongly recommend reading through the entire writeup before you begin – it is only 2.5 more pages of writing after this.
Implementation Requirements Overview
For this program, you will be implementing two classes from Javadocs as well as one tester file. We have again provided the tester file and the full implementation of TWO of the tester methods, one focused on the correctness of the PatientRecord class and another verifying the performance of the addPatient() method under error conditions. You must complete the other tester methods using the suggested scenarios to verify that your program works as specified.
PatientRecord
The PatientRecord class is our replacement for the 3-element int array from P01, which represented a patient’s caseID/arrival order/triage level. This object version will allow us to mix and match types, and includes a couple of simple behaviors – instead of assigning arbitrary caseID values, you’ll implement a utility method to create them based on some patient characteristics.
Additionally, this class overrides the Object method toString() so that you can do the following:
PatientRecord test = new PatientRecord('M', 18, GREEN);
System.out.println(test);
and get meaningful output. This also provides a convenient way to check whether two patients are the same without also overriding the equals() method – you can check whether their String representations are the same:
if ( record1.toString().equals(record2.toString()) ) {
System.out.println("These are the same patient");
}
ExceptionalCareAdmissions
Rather than a static class with utility methods, we will implement this iteration of the methods as instance methods attached to an ExceptionalCareAdmissions object. This way we could manage multiple separate urgent care waiting lists using the same program.
Many of the methods here will be familiar, and you are welcome to refactor your implementation from P01 if you like!
The major difference is that now we can mark patients as having been seen WITHOUT removing them from the patientsList. Removing seen patients now happens in the cleanPatientsList()
method, which maintains a file record of the seen patients that it removes from the array. For testing purposes, we provide you with the following toString() method for this class:
/**
* For testing purposes: this method creates and returns a string representation of the
* patientsList, as the in-order string representation of each patient in the list on a
* separate line. If patientsList is empty, returns an empty string.
*
* @return a string representation of the contents of patientsList
*/
public String toString() {
String returnValue = "";
for (PatientRecord r : patientsList) {
returnValue += (r != null) ? r.toString()+"\n" : "";
}
return returnValue.trim();
}
To check the current contents of the patientsList array, you can use the output of this method.
ExceptionalCareTester
The tester class starter file is provided for you on the assignment page. We’ve included the full implementation of TWO of the methods, since there are rather a lot of them. These two methods are heavily commented and are intended to provide you a model to work from both on this assignment and in the future when testing other instantiable classes and methods which throw exceptions.
For the rest of the tester file, we have divided the test cases up into many smaller methods so you can better diagnose when problems occur.
In all tester methods in CS 300, you must catch ANY and ALL exceptions thrown by the method you are testing, even if they are not the type of exception you are expecting.
Implementation Details and Suggestions
We suggest beginning by reading the javadocs and the tester method for PatientRecord in the provided tester class, and then completing the PatientRecord implementation. Verify it using the tester class.
Then move on to the ExceptionalCareAdmissions class. Add the required methods from the javadocs as stubs (with default return values), and begin moving back and forth between the methods and their testers to complete the assignment. Don’t forget to add the toString() method from the previous section!
As you complete the tester class, you may wish to add additional printed output to help you diagnose issues. That’s fine, as long as the method still returns false if any of your test scenarios fail or true if they all pass; the autograder will again run your tests on my (Hobbes’) implementation AND an implementation that doesn’t work the way it should in some way, so make sure you can tell the difference!
cleanPatientsList() example
To give you an example of how the cleanPatientsList() method works, consider the following abbreviated representation of an ExceptionalCareAdmissions’ patientsList with length 5 and size 4 (note that not all “seen” patients need be at the front of the array):
[ [21701: 17M (YELLOW) - seen], [10404: 4F (YELLOW) - not seen],
[32102: 21X (GREEN) - seen], [11703: 17F (GREEN) - not seen], null ]
If we were to run cleanPatientsList() on the ExceptionalCareAdmissions object that contains this patientsList, the resulting array would have size 2 and the following contents:
[ [10404: 4F (YELLOW) - not seen], [11703: 17F (GREEN) - not seen],
null, null, null ]
And the file would contain the following contents:
Total number of patients: 4
Total number seen: 2
RED: 0
YELLOW: 2
GREEN: 2
21701: 17M (YELLOW)
32102: 21X (GREEN)
Assignment Submission
Once you’re satisfied with your work, both in terms of adherence to this specification and the academic conduct and style guide requirements, submit your source code through Gradescope. For full credit, please submit ONLY the following files (source code, not .class files):
● ExceptionalCareAdmissions.java
● ExceptionalCareTester.java
● PatientRecord.java
Your score for this assignment will be based on the submission marked “active” prior to the deadline. You may select which submission to mark active at any time, but by default this will be your most recent submission.
Copyright notice
This assignment specification is the intellectual property of Mouna Ayari Ben Hadj Kacem, Hobbes LeGault, and the University of Wisconsin– Madison and may not be shared without express, written permission.
Additionally, students are not permitted to share source code for their CS 300 projects on any public site.
2023-03-03
P04 Exceptional Care