Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class PatientPrioritizer {
- public static final int HOSPITAL_ZIP = 12345;
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- //Variable Intialization
- int priorityScore = 0;
- int patientNum = 0;
- String scoreZ = "";
- welcomeMessage();
- String patientName = usersName(console);
- while (!patientName.equals("quit")){
- patientNum++;
- priorityScore = theNums(console, patientName, priorityScore);
- scoreZ += priorityScore;
- patientName = usersName(console);
- } // end of while loop
- dailyStatistics(scoreZ, patientNum);
- } // end of main method
- //This method prints out a series of strings to welcome/instruct the user
- //Parameters: none
- //Return: none
- public static void welcomeMessage(){
- System.out.println("Hello! We value you and your time, so we will help");
- System.out.println("you prioritize which patients to see next!");
- System.out.println("Please answer the following questions about the next patient so");
- System.out.println("we can help you do your best work :)");
- System.out.println();
- } // end of welcomeMessage method
- //This method collects the patient's name or recieves a respone "quit" which quits the program
- //Parameters: Scanner console
- //Return: String name (also known as patientName)
- public static String usersName(Scanner console){
- System.out.println("Please enter the next patient\'s name"
- + " or \"quit\" to end the program.");
- System.out.print("Patient\'s name: ");
- String name = console.nextLine();
- return name;
- } // end of usersName method
- //This method holds & stores user input values for priority score calculation
- //Parameters: Scanner Console, String patientName, int priorityScore (final calculation)
- //Return: priorityScore (so it can be used in a later method)
- public static int theNums(Scanner console, String patientName, int priorityScore){
- System.out.print("Patient age: ");
- int age = console.nextInt();
- System.out.print("Patient zip code: ");
- int zipCode = console.nextInt();
- boolean five = fiveDigits(zipCode);
- while(!five){
- zipCode = console.nextInt();
- five = fiveDigits(zipCode);
- } // end of while loop
- System.out.print("Is our hospital \"in network\" for the patient's insurance? ");
- String insurance = console.next();
- insuranceCheck(insurance);
- System.out.print("Patient pain level (1-10): ");
- int painLevel = console.nextInt();
- boolean pLT = painLevelTest(painLevel);
- while(!pLT){
- painLevel = console.nextInt();
- pLT = painLevelTest(painLevel);
- } // end of while loop
- System.out.print("Patient temperature (in degrees Fahrenheit): ");
- double temperature = console.nextDouble();
- console.nextLine();
- priorityScore = calculatingPriorityScore(age, zipCode, painLevel,
- temperature, insurance, priorityScore);
- priorityLevel(patientName, priorityScore);
- System.out.println();
- System.out.println("Thank you for using our system!");
- System.out.println("We hope we have helped you do your best!");
- System.out.println();
- return priorityScore;
- } // end of theNums method
- //This method takes in numerous variables and calculates a score using if statments
- /*Parameters: int age, int zipCode, int painLevel,
- double temperature, String insurance, int priorityScore*/
- //Return: priorityScore (updated through calculations)
- public static int calculatingPriorityScore(int age, int zipCode, int painLevel,
- double temperature, String insurance,
- int priorityScore){
- int baseScore = 100;
- if(age >= 75 || age < 12){
- baseScore += 50;
- }
- if(HOSPITAL_ZIP/10000 == zipCode/10000){
- baseScore += 25;
- }
- if((HOSPITAL_ZIP/10000 == zipCode/10000) && (HOSPITAL_ZIP/1000 == zipCode/1000)){
- baseScore += 15;
- }
- if(insurance.equals("y") || insurance.equals("yes")){
- baseScore += 50;
- }
- baseScore += (painLevel * 10);
- if (temperature > 99.5){
- baseScore += 8;
- }
- priorityScore = baseScore;
- return priorityScore;
- } //end of calculatingPriorityScore method
- //This method prints out the patient's priority and priority level
- //Parameters: String patientsName, int priorityScore
- //Return: none
- public static void priorityLevel(String patientName, int priorityScore){
- System.out.print("We have found patient " + patientName);
- System.out.println(" to have a priority score of: " + priorityScore);
- System.out.print("We have determined this patient is ");
- if (priorityScore >= 333){
- System.out.println("high priority,");
- System.out.println("and it is advised to call an appropriate medical provider ASAP.");
- }else if (priorityScore < 333 && priorityScore >= 168){
- System.out.println("medium priority.");
- System.out.println("Please assign an appropriate medical provider to their case");
- System.out.println("and check back in with the patient's condition in a little while.");
- }else {
- System.out.println("low priority.");
- System.out.print("Please put them on the waitlist for");
- System.out.println(" when a medical provider becomes available.");
- }
- } // end of priorityLevel method
- //This method finds the max score and prints out the max & the # of patients
- /*Parameters: String scoreZ (priorityScores as a String to run comparisions),
- int patientNum (number of patients helped that day)*/
- //Return: none
- public static void dailyStatistics(String scoreZ, int patientNum){
- int scorezLength = scoreZ.length();
- int maxPriorityScore = 0;
- if(scorezLength != 0){
- maxPriorityScore = Integer.valueOf(scoreZ.substring(0,3));
- for(int i = 3; i < scorezLength; i += 3){
- int otherScore = Integer.valueOf(scoreZ.substring (i, i + 3));
- if(maxPriorityScore < otherScore){
- maxPriorityScore = otherScore;
- } // end of inner if statment
- } // end of for loop
- } // end of outer if statement
- System.out.println("Statistics for the day:");
- System.out.println("..." + patientNum + " patients were helped");
- System.out.println("...the highest priority patient we saw had a score of "
- + maxPriorityScore);
- System.out.println("Good job today!");
- } // end of dailyStatistics method
- //This method tests to see if user input, zipCode, is 5 digits or not
- //Parameters: int val (the zipCode that the user inputed)
- //Return: returns whether or not the zipCode is 5 digits
- public static boolean fiveDigits(int val) {
- val = val / 10000; // get first digit
- if (val == 0) { // has less than 5 digits
- System.out.print("Invalid zip code, enter valid zip code: ");
- return false;
- } else if (val / 10 == 0) { // has 5 digits
- return true;
- } else { // has more than 5 digits
- System.out.print("Invalid zip code, enter valid zip code: ");
- return false;
- }
- } // end of fiveDigits method
- //This method checks whether or not the painLevel is within the range of 1-10
- //Parameters: int val (the painLevel the user inputed)
- //Return: returns whether or not the painLevel is within range
- public static boolean painLevelTest (int val) {
- if (val >= 1 && val <= 10) {
- return true;
- } else {
- System.out.print("Invalid pain level, enter valid pain level (1-10): ");
- return false;
- }
- } // end of painLevelTest method
- //This method checks to see if the user has insurance or not
- //Parameters: String insurance (String-based user input)
- //Return: returns whether or not the user has insurance
- public static boolean insuranceCheck (String insurance){
- if(insurance.equals("yes") || insurance.equals("y")){
- return true;
- } else
- return false;
- } // end of insuranceCheck method
- } // end of public class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement