Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. /*
  2. * file : PROGRAM_04
  3. * name : Devin Weller
  4. * course : CS116*02 MW (Winter 2017)
  5. * description: Process input file to print formatted data and summary data
  6. */
  7.  
  8. package program04;
  9.  
  10. import java.util.Scanner;
  11.  
  12. /**
  13. */
  14. public class Program04
  15. {
  16.  
  17. // TODO Declare and initialise class variables here
  18.  
  19. /**
  20. * @param args
  21. */
  22. public static void main(String[] args)
  23. {
  24.  
  25. // TODO: Declare and initialise local variables here:
  26. // isValid
  27.  
  28. boolean isValid;
  29.  
  30. String patientName;
  31. int patientID;
  32. String gender;
  33. float exam1, exam2, exam3;
  34. double avg;
  35. String pos_neg; // will always be a color
  36.  
  37.  
  38. // System.out.println top line of report
  39. System.out.println("*~~< Patient Exam Report >~~*");
  40. // System.out.println blank line
  41. System.out.println("");
  42. // Name Pat. M/F Exam1 Exam2 Exam3 AVG Risk Level
  43. // ---- ---- --- ----- ----- ----- ----- ----------
  44. // print words
  45. // print column headers;
  46. System.out.printf("%-12s", "Name");
  47. System.out.printf("%-13s", "Pat.");
  48. System.out.printf("%-8s", "M/F");
  49. System.out.printf("%-8s", "Exam1");
  50. System.out.printf("%-8s", "Exam2");
  51. System.out.printf("%-8s", "Exam3");
  52. System.out.printf("%-6s", "AVG");
  53. System.out.printf("%-13s", "Risk Level \n");
  54. // print dashes
  55. System.out.printf("%-12s", "----");
  56. System.out.printf("%-13s", "----");
  57. System.out.printf("%-8s", "---");
  58. System.out.printf("%-8s", "----");
  59. System.out.printf("%-8s", "----");
  60. System.out.printf("%-8s", "----");
  61. System.out.printf("%-6s", "----");
  62. System.out.printf("%-13s", "----------\n");
  63.  
  64. Scanner input = new Scanner(System.in);
  65.  
  66. for (int i = 0; i < 10; i++) {
  67.  
  68. // input(patientName) / print;
  69. patientName = input.next();
  70. System.out.printf("%-12s", patientName);
  71.  
  72. // input(patientID)
  73. patientID = input.nextInt();
  74. System.out.printf("%-13s", patientID);
  75.  
  76. // input(gender);
  77. gender = input.next();
  78. System.out.printf("%-8s", gender);
  79.  
  80. // input(exam1);
  81. exam1 = input.nextFloat();
  82. System.out.printf("%-8.2f", exam1);
  83.  
  84. // input(exam2);
  85. exam2 = input.nextFloat();
  86. System.out.printf("%-8.2f", exam2);
  87.  
  88. // input(exam3);
  89. exam3 = input.nextFloat();
  90. System.out.printf("%-8.2f", exam3);
  91.  
  92.  
  93. // Create isValid variable to equal true unless if/else statement fails it changes to false
  94. // If true, do nothing... If false, Print "Invalid data"
  95. isValid = true;
  96. if (1111 <= patientID && patientID <= 9999) {
  97. }
  98. else {
  99. isValid = false;
  100. }
  101. if (0.00 <= exam1 && exam1 <= 100.00) {
  102. }
  103. else {
  104. isValid = false;
  105. }
  106. if (0.00 <= exam2 && exam2 <= 100.00) {
  107. }
  108. else {
  109. isValid = false;
  110. }
  111. if (0.00 <= exam3 && exam3 <= 100.00) {
  112. }
  113. else {
  114. isValid = false;
  115. }
  116.  
  117. if (isValid == true) {
  118. // Find Average
  119. avg = (exam1 + exam2 + exam3) / 3;
  120. System.out.printf("%-6.2f", avg);
  121. // If else statement to decide if average is above X number Print Y
  122. if (avg >= 97) {
  123. System.out.printf("%-13s", "RED\n");
  124. } else if (avg > 88) {
  125. System.out.printf("%-13s", "ORANGE\n");
  126. }
  127. else if (avg > 78) {
  128. System.out.printf("%-13s", "YELLOW\n");
  129. }
  130. else if (avg > 70) {
  131. System.out.printf("%-13s", "BLUE\n");
  132. }
  133. else {
  134. System.out.printf("%-13s", "GREEN\n"); }
  135. }
  136. else {
  137. System.out.println("~~ Invalid data~~\n");
  138. }
  139. }
  140.  
  141. System.out.println(" ");
  142. System.out.println("*< end of report >*");
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement