Question
I have this assignment but I'm not sure what my mistakes are. I have done the overall flow of the code. I am having problems
I have this assignment but I'm not sure what my mistakes are. I have done the overall flow of the code. I am having problems with the display of maximum and minimum. I am not sure how to get the information from the different classes to present the output accordingly.
I am also having trouble with displaying the information and obtaining the information from the text file. I want to double check and get your advice on how to go about solving this issues.
Code:
import java.util.Scanner; import java.io.IOException; import java.io.File;
enum Month{Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}
class Date { //instance variable private int day; private Month month; private int year; //Constructors public Date () { } public Date (int day, Month month, int year) { this.day = day; this.month = month; this.year = year; } public Date (Date d) { this.day = d.day; this.month = d.month; this.year = d.year; } //Accessor methods public int getDay () { return day; } public Month getMonth () { return month; } public int getYear () { return year; } public void setDate (int day, Month month, int year) { this.day = day; this.month = month; this.year = year; } }
class HeartRates { //instance variables private String firstName; private String lastName; private Date dob; int currentYear; //Constructors 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.firstName = hr.firstName; this.lastName = hr.lastName; this.dob = hr.dob; this.currentYear = hr.currentYear; } //Accessor methods public String getFirstName () { return firstName; } public String getLastName () { return lastName; } public Date getDOB () { return dob; } public int getAge () { int userAge = currentYear - getYear(); return userAge; } public int getMaximumHeartRate() { int userAge = getAge(); int maxHeartRate = 220 - userAge; return maxHeartRate; } public double getMinimumTargetHeartRate() { int maxHeartRate = getMaximumHeartRate(); // minimum = maxheart * 50/100 double minTargetHRate = maxHeartRate * 0.5 ; return minTargetHRate; } public double getMaximumTargetHeartRate () { int maxHeartRate = getMaximumHeartRate(); // maximum = maxheart * 85/100 double maxTargetHRate = maxHeartRate * 0.85 ; return maxTargetHRate; } //Mutator methods public void setFirstName () { this.firstName = firstName; } public void setDob () { this.dob = dob; } public void printInfo () { System.out.printf ("Name: %s%n" , firstName, lastName); System.out.printf ("Date of birth: %s%n", dob); System.out.printf ("Current year: %s%n", currentYear); System.out.printf ("Clinic analysis, base on your age: %s%n", userAge() ); System.out.printf ("1. Your maximum heart rate is %s%n" , getMaximumHeartRate() ); System.out.printf ("2. Your minimum target heart rate is %s%n", getMinimumTargetHeartRate () ); System.out.printf (" 3. Your maximum target heart rate is %s%n", getMaximumTargetHeartRate() ); } }
class HeartRatesTest { public static void main (String [] args) throws IOException { Scanner input = new Scanner (new File ("Collin_Assignment2.txt")); //Read info from the data file String firstName = input.nextLine(); String lastName = input.nextLine (); Date dob = input.nextLine(); int currentYear = input.nextInt(); HealthRates HR = new HealthRates (firstName, lastName, currentYear, dob);
hrr1.printInfo(); input.nextLine (); } }
the text in the notepad (text file)
Ah Beng Tan 15 Oct 1988 2018
Robert Richard Wong 31 Dec 2005 2018
Let us explore the following UML diagram:Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started