Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Full name: Pranish Daryanani
- // Full time
- // Tutorial Group T02
- // Declaration: This work is completely done by Pranish (me).
- // I have not shared this work with anyone else.
- // I accept any penalty that must be given.
- //imports
- import java.io.File;
- import java.io.IOException;
- import java.util.Scanner;
- //state enum
- enum Month
- {
- Jan, Feb, Mar, Apr,
- May, Jun, Jul, Aug,
- Sep, Oct, Nov, Dec
- }
- //new class Date
- class Date
- {
- private int day;
- private Month month;
- private int year;
- //month relation (enum)
- public Date()
- {
- setDate(1, Month.Jan, 2020);
- }
- public Date(int day, Month month, int year)
- {
- setDate(day, month, year);
- }
- public Date(Date d)
- {
- setDate(d.getDay(), d.getMonth(), d.getYear());
- }
- public int getDay()
- {
- return this.day;
- }
- public Month getMonth()
- {
- return this.month;
- }
- public int getYear()
- {
- return this.year;
- }
- public void setDate(int day, Month month, int year)
- {
- this.day = day;
- this.month = month;
- this.year = year;
- }
- }
- //new class HeartRates
- class HeartRates
- {
- private String firstName;
- private String lastName;
- private Date dob;
- private int currentYear;
- public HeartRates(String firstName, String lastName, Date dob, int currentYear)
- {
- this.firstName = firstName;
- this.lastName = lastName;
- this.dob = dob;
- this.currentYear = currentYear;
- }
- public HeartRates(HeartRates hr)
- {
- this(hr.getFirstName(), hr.getLastName(), hr.getDOB(), hr.getCurrentYear());
- }
- public String getFirstName()
- {
- return this.firstName;
- }
- public String getLastName()
- {
- return this.lastName;
- }
- public Date getDOB() {
- return this.dob;
- }
- public int getCurrentYear() {
- return this.currentYear;
- }
- public void setFirstName(String firstName)
- {
- this.firstName = firstName;
- }
- public void setLastName(String lastName)
- {
- this.lastName = lastName;
- }
- public void setDOB(Date dob)
- {
- this.dob = dob;
- }
- public void setCurrentYear(int currentYear)
- {
- this.currentYear = currentYear;
- }
- //calcs
- public int getAge()
- {
- return currentYear - dob.getYear();
- }
- public int getMaximumHeartRate()
- {
- return 220 - getAge();
- }
- public double getMinimumTargetHeartRate()
- {
- return 0.5 * getMaximumHeartRate();
- }
- public double getMaximumTargetHeartRate()
- {
- return 0.85 * getMaximumHeartRate();
- }
- //printf details
- public void printInfo()
- {
- System.out.printf("Name: %s, %s\n", firstName, lastName);
- System.out.printf("Date of Birth: %d %s %d\n", dob.getDay(), String.valueOf(dob.getMonth()), dob.getYear());
- System.out.printf("Current year: %d\n", currentYear);
- System.out.printf("Your age: %d years old\n", getAge());
- System.out.printf("Clinic analysis, based on your age:\n");
- System.out.printf(" 1. Your maximum heart rate is %d\n",getMaximumHeartRate());
- System.out.printf(" 2. Your minimum target heart rate is %.2f\n",getMinimumTargetHeartRate());
- System.out.printf(" 3. Your maximum target heart rate is %.2f\n",getMaximumTargetHeartRate());
- }
- }
- //new class HeartRatesTest (run this once compiled)
- class HeartRatesTest
- {
- public static void main(String[] args) throws IOException
- {
- Scanner s = new Scanner(new File("fileinput.txt")); //importing the textfile with the details
- for(int i = 0; i < 2; i++)
- {
- // link first and last name
- String firstName = s.nextLine();
- String lastName = s.nextLine();
- // link date, month, and year
- int bDate = s.nextInt();
- Month bMonth = Month.valueOf(s.next());
- int bYear = s.nextInt();
- // new object (date)
- Date d = new Date(bDate, bMonth, bYear);
- // link current year
- int currentYear = s.nextInt();
- // Clear buffer queue (clear to get next)
- s.nextLine();
- // Create the HeartRates object
- HeartRates h = new HeartRates(firstName, lastName, d, currentYear);
- h.printInfo();
- System.out.printf("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement