Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * file : PROGRAM_04
- * name : Devin Weller
- * course : CS116*02 MW (Winter 2017)
- * description: Process input file to print formatted data and summary data
- */
- package program04;
- import java.util.Scanner;
- /**
- */
- public class Program04
- {
- // TODO Declare and initialise class variables here
- /**
- * @param args
- */
- public static void main(String[] args)
- {
- // TODO: Declare and initialise local variables here:
- // isValid
- boolean isValid;
- String patientName;
- int patientID;
- String gender;
- float exam1, exam2, exam3;
- double avg;
- String pos_neg; // will always be a color
- // System.out.println top line of report
- System.out.println("*~~< Patient Exam Report >~~*");
- // System.out.println blank line
- System.out.println("");
- // Name Pat. M/F Exam1 Exam2 Exam3 AVG Risk Level
- // ---- ---- --- ----- ----- ----- ----- ----------
- // print words
- // print column headers;
- System.out.printf("%-12s", "Name");
- System.out.printf("%-13s", "Pat.");
- System.out.printf("%-8s", "M/F");
- System.out.printf("%-8s", "Exam1");
- System.out.printf("%-8s", "Exam2");
- System.out.printf("%-8s", "Exam3");
- System.out.printf("%-6s", "AVG");
- System.out.printf("%-13s", "Risk Level \n");
- // print dashes
- System.out.printf("%-12s", "----");
- System.out.printf("%-13s", "----");
- System.out.printf("%-8s", "---");
- System.out.printf("%-8s", "----");
- System.out.printf("%-8s", "----");
- System.out.printf("%-8s", "----");
- System.out.printf("%-6s", "----");
- System.out.printf("%-13s", "----------\n");
- Scanner input = new Scanner(System.in);
- for (int i = 0; i < 10; i++) {
- // input(patientName) / print;
- patientName = input.next();
- System.out.printf("%-12s", patientName);
- // input(patientID)
- patientID = input.nextInt();
- System.out.printf("%-13s", patientID);
- // input(gender);
- gender = input.next();
- System.out.printf("%-8s", gender);
- // input(exam1);
- exam1 = input.nextFloat();
- System.out.printf("%-8.2f", exam1);
- // input(exam2);
- exam2 = input.nextFloat();
- System.out.printf("%-8.2f", exam2);
- // input(exam3);
- exam3 = input.nextFloat();
- System.out.printf("%-8.2f", exam3);
- // Create isValid variable to equal true unless if/else statement fails it changes to false
- // If true, do nothing... If false, Print "Invalid data"
- isValid = true;
- if (1111 <= patientID && patientID <= 9999) {
- }
- else {
- isValid = false;
- }
- if (0.00 <= exam1 && exam1 <= 100.00) {
- }
- else {
- isValid = false;
- }
- if (0.00 <= exam2 && exam2 <= 100.00) {
- }
- else {
- isValid = false;
- }
- if (0.00 <= exam3 && exam3 <= 100.00) {
- }
- else {
- isValid = false;
- }
- if (isValid == true) {
- // Find Average
- avg = (exam1 + exam2 + exam3) / 3;
- System.out.printf("%-6.2f", avg);
- // If else statement to decide if average is above X number Print Y
- if (avg >= 97) {
- System.out.printf("%-13s", "RED\n");
- } else if (avg > 88) {
- System.out.printf("%-13s", "ORANGE\n");
- }
- else if (avg > 78) {
- System.out.printf("%-13s", "YELLOW\n");
- }
- else if (avg > 70) {
- System.out.printf("%-13s", "BLUE\n");
- }
- else {
- System.out.printf("%-13s", "GREEN\n"); }
- }
- else {
- System.out.println("~~ Invalid data~~\n");
- }
- }
- System.out.println(" ");
- System.out.println("*< end of report >*");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement