Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. // Full name: Pranish Daryanani
  2. // Full time
  3. // Tutorial Group T02
  4. // Declaration: This work is completely done by Pranish (me).
  5. // I have not shared this work with anyone else.
  6. // I accept any penalty that must be given.
  7.  
  8.  
  9. //imports
  10. import java.io.File;
  11. import java.io.IOException;
  12. import java.util.Scanner;
  13.  
  14.  
  15. //state enum
  16. enum Month
  17. {
  18. Jan, Feb, Mar, Apr,
  19. May, Jun, Jul, Aug,
  20. Sep, Oct, Nov, Dec
  21. }
  22.  
  23. //new class Date
  24. class Date
  25. {
  26. private int day;
  27. private Month month;
  28. private int year;
  29.  
  30.  
  31. //month relation (enum)
  32. public Date()
  33. {
  34. setDate(1, Month.Jan, 2020);
  35. }
  36.  
  37. public Date(int day, Month month, int year)
  38. {
  39. setDate(day, month, year);
  40. }
  41.  
  42.  
  43. public Date(Date d)
  44. {
  45. setDate(d.getDay(), d.getMonth(), d.getYear());
  46. }
  47.  
  48.  
  49. public int getDay()
  50. {
  51. return this.day;
  52. }
  53.  
  54. public Month getMonth()
  55. {
  56. return this.month;
  57. }
  58.  
  59. public int getYear()
  60. {
  61. return this.year;
  62. }
  63.  
  64. public void setDate(int day, Month month, int year)
  65. {
  66. this.day = day;
  67. this.month = month;
  68. this.year = year;
  69. }
  70. }
  71.  
  72. //new class HeartRates
  73. class HeartRates
  74. {
  75. private String firstName;
  76. private String lastName;
  77. private Date dob;
  78. private int currentYear;
  79.  
  80.  
  81. public HeartRates(String firstName, String lastName, Date dob, int currentYear)
  82. {
  83. this.firstName = firstName;
  84. this.lastName = lastName;
  85. this.dob = dob;
  86. this.currentYear = currentYear;
  87. }
  88.  
  89.  
  90. public HeartRates(HeartRates hr)
  91. {
  92. this(hr.getFirstName(), hr.getLastName(), hr.getDOB(), hr.getCurrentYear());
  93. }
  94.  
  95.  
  96. public String getFirstName()
  97. {
  98. return this.firstName;
  99. }
  100.  
  101. public String getLastName()
  102. {
  103. return this.lastName;
  104. }
  105.  
  106. public Date getDOB() {
  107. return this.dob;
  108. }
  109.  
  110. public int getCurrentYear() {
  111. return this.currentYear;
  112. }
  113.  
  114.  
  115. public void setFirstName(String firstName)
  116. {
  117. this.firstName = firstName;
  118. }
  119.  
  120. public void setLastName(String lastName)
  121. {
  122. this.lastName = lastName;
  123. }
  124.  
  125. public void setDOB(Date dob)
  126. {
  127. this.dob = dob;
  128. }
  129.  
  130. public void setCurrentYear(int currentYear)
  131. {
  132. this.currentYear = currentYear;
  133. }
  134.  
  135.  
  136. //calcs
  137. public int getAge()
  138. {
  139. return currentYear - dob.getYear();
  140. }
  141.  
  142. public int getMaximumHeartRate()
  143. {
  144. return 220 - getAge();
  145. }
  146.  
  147. public double getMinimumTargetHeartRate()
  148. {
  149. return 0.5 * getMaximumHeartRate();
  150. }
  151.  
  152. public double getMaximumTargetHeartRate()
  153. {
  154. return 0.85 * getMaximumHeartRate();
  155. }
  156.  
  157.  
  158. //printf details
  159. public void printInfo()
  160. {
  161. System.out.printf("Name: %s, %s\n", firstName, lastName);
  162.  
  163. System.out.printf("Date of Birth: %d %s %d\n", dob.getDay(), String.valueOf(dob.getMonth()), dob.getYear());
  164.  
  165. System.out.printf("Current year: %d\n", currentYear);
  166.  
  167. System.out.printf("Your age: %d years old\n", getAge());
  168.  
  169. System.out.printf("Clinic analysis, based on your age:\n");
  170.  
  171. System.out.printf(" 1. Your maximum heart rate is %d\n",getMaximumHeartRate());
  172.  
  173. System.out.printf(" 2. Your minimum target heart rate is %.2f\n",getMinimumTargetHeartRate());
  174.  
  175. System.out.printf(" 3. Your maximum target heart rate is %.2f\n",getMaximumTargetHeartRate());
  176. }
  177. }
  178.  
  179. //new class HeartRatesTest (run this once compiled)
  180.  
  181. class HeartRatesTest
  182. {
  183. public static void main(String[] args) throws IOException
  184. {
  185. Scanner s = new Scanner(new File("fileinput.txt")); //importing the textfile with the details
  186.  
  187. for(int i = 0; i < 2; i++)
  188. {
  189. // link first and last name
  190. String firstName = s.nextLine();
  191. String lastName = s.nextLine();
  192.  
  193. // link date, month, and year
  194. int bDate = s.nextInt();
  195. Month bMonth = Month.valueOf(s.next());
  196. int bYear = s.nextInt();
  197.  
  198. // new object (date)
  199. Date d = new Date(bDate, bMonth, bYear);
  200.  
  201. // link current year
  202. int currentYear = s.nextInt();
  203.  
  204. // Clear buffer queue (clear to get next)
  205. s.nextLine();
  206.  
  207. // Create the HeartRates object
  208. HeartRates h = new HeartRates(firstName, lastName, d, currentYear);
  209. h.printInfo();
  210.  
  211.  
  212. System.out.printf("\n");
  213. }
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement