Question: Why my code has wrong output on weight, current year, age, and heart beat? can you find and give me the correct code plz? my

Why my code has wrong output on weight, current year, age, and heart beat? can you find and give me the correct code plz?

my output is this

First patient --------------

Name: Mohamed Ali, Bin Abdullah Date of birth: 15 Oct 1951 Your weight: 0.0 kg Your height: 5 feet 6 inches; equivalent to: 1.68 meter Current year: 0 Your age: -1951 years old Clinic analysis, base on your age: 1. Your maximum heart rate is 2171 2. Your minimum target heart rate is 1085.50 3. Your maximum target heart rate is 1845.35 Your BMI 0.0 Weight Category Range Underweight / too low Below 18.5 Healthy range 18.5 - 25 Overweight 25 - 30 Obese 30 - 35 Severe Obesity 35 - 40 Morbid Obesity Over 40

Second patient --------------

Name: Alan Rochard, Heng Date of birth: 31 Dec 2005 Your weight: 0.0 kg Your height: 6 feet 8 inches; equivalent to: 2.03 meter Current year: 0 Your age: -2005 years old Clinic analysis, base on your age: 1. Your maximum heart rate is 2225 2. Your minimum target heart rate is 1112.50 3. Your maximum target heart rate is 1891.25 Your BMI 0.0 Weight Category Range Underweight / too low Below 18.5 Healthy range 18.5 - 25 Overweight 25 - 30 Obese 30 - 35 Severe Obesity 35 - 40 Morbid Obesity Over 40

but it should be this

Why my code has wrong output on weight, current year, age, andwith this input txtheart beat? can you find and give me the correct code plz? file

------

import java.util.Scanner;

import java.io.File;

import java.io.IOException;

enum Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};

class Date{

private int day;

private Month month;

private int year;

//default constructor

public Date()

{

this.day = 1;

this.month = Month.Jan;

this.year = 2023;

}

//other constructor

public Date (int day, Month month, int year)

{

this.day = day;

this.month = month;

this.year =year;

}

//copy constructor

public Date(Date d)

{

this(d.day, d.month, d.year);

}

// Accessor methods

public int getDay()

{

return day;

}

public Month getMonth()

{

return month;

}

public int getYear()

{

return year;

}

//mutator methods

public void setDate(int day, Month month, int year)

{

this.day = day;

this.month = month;

this.year = year;

}

}

class Height

{

private int feet;

private int inches;

//default constructor

public Height()

{

this.feet = feet;

this.inches = inches;

}

//other constructor

public Height(int feet, int inches)

{

this.feet = feet;

this.inches = inches;

}

//copy constructor

public Height(Height h)

{

this(h.feet, h.inches);

}

// Accessor methods

public int getFeet()

{

return feet;

}

public int getInches()

{

return inches;

}

// Mutator method

public void setHeight(int feet, int inches)

{

this.feet = feet;

this.inches = inches;

}

// feet to meters

public double getMeters()

{

double meters = feet * 0.3048;

return meters;

}

// Convert inches to meters

public double getCentimeters()

{

double centimeters = inches * 0.0254;

return centimeters;

}

public double getHeightInMeter()

{

double heightinmeter = getMeters() + getCentimeters();

return heightinmeter;

}

}

class Name {

private String firstName;

private String lastName;

public Name(String firstName, String lastName)

{

this.firstName = firstName;

this.lastName = lastName;

}

public Name(Name n)

{

this(n.firstName, n.lastName);

}

// Accessor methods

public String getFirstName()

{

return firstName;

}

public String getLastName()

{

return lastName;

}

public void setName(String firstName, String lastName)

{

this.firstName = firstName;

this.lastName = lastName;

}

public void displayInfo()

{

System.out.printf("%nName: %s, %s%n", firstName, lastName);

}

}

class HealthProfile{

private Name name;

private Date dob;

private Height h;

private double weight;

private int currentYear;

//constuctor

public HealthProfile(Name name, Date dob, Height h, double weight, int currentYear)

{

this.name = name;

this.dob = dob;

this.h = h;

}

public HealthProfile(HealthProfile hr)

{

this(hr.name, hr.dob, hr.h, hr.weight, hr.currentYear);

}

public Name getName()

{

return name;

}

public void setName(Name name)

{

this.name = name;

}

public Date getDOB()

{

return dob;

}

public Height getHeight()

{

return h;

}

public double getweight()

{

return weight;

}

public void setDOB(Date dob)

{

this.dob = dob;

}

public void setHeight(Height h)

{

this.h = h;

}

public int getCurrentYear()

{

return currentYear;

}

public void setCurrentYear(int currentYear)

{

this.currentYear = currentYear;

}

public int getAge()

{

int age = currentYear - dob.getYear();

return age;

}

public int getMaximumHeartRate()

{

int maxHR = 220 - getAge();

return maxHR;

}

public double getMinimumTargetHeartRate()

{

double minTHR = getMaximumHeartRate()*0.5;

return minTHR;

}

public double getMaximumTargetHeartRate()

{

double maxTHR = getMaximumHeartRate() * 0.85;

return maxTHR;

}

public double getBMI()

{

double bmi = weight / (h.getHeightInMeter() * h.getHeightInMeter());

return bmi;

}

public void displayInfo()

{

name.displayInfo();

System.out.printf("Date of birth: %d %s %d%n", dob.getDay(),

String.valueOf(dob.getMonth()), dob.getYear());

System.out.printf("Your weight: %.1f kg ", weight);

System.out.printf("Your height: %d feet %d inches; equivalent to: %.2f meter ",

h.getFeet(), h.getInches(), h.getHeightInMeter());

System.out.printf("Current year: %d%n", currentYear);

System.out.printf("Your age: %d years old ", getAge());

System.out.printf("Clinic analysis, base on your age: ");

System.out.printf("\t1. Your maximum heart rate is %d%n", getMaximumHeartRate());

System.out.printf("\t2. Your minimum target heart rate is %.2f%n",

getMinimumTargetHeartRate());

System.out.printf("\t3. Your maximum target heart rate is %.2f%n",

getMaximumTargetHeartRate());

System.out.printf("Your BMI %.1f%n", getBMI());

System.out.printf("\t%-25s %s%n", "Weight Category", "Range");

System.out.printf("\t%-25s %s%n", "Underweight / too low", "Below 18.5");

System.out.printf("\t%-25s %s%n", "Healthy range", "18.5 - 25");

System.out.printf("\t%-25s %s%n", "Overweight", "25 - 30");

System.out.printf("\t%-25s %s%n", "Obese", "30 - 35");

System.out.printf("\t%-25s %s%n", "Severe Obesity", "35 - 40");

System.out.printf("\t%-25s %s%n", "Morbid Obesity", "Over 40");

}

}

class A2

{

public static void main (String [] args) throws IOException

{

// Construct a Scanner class object, link to data file called input.txt

Scanner input = new Scanner (new File("/Users/yoon/Desktop/_A1/input.txt"));

// Declare private variables

Name name;

Date dob = new Date();

Height h = new Height();

double weight;

int currentYear;

name = new Name(input.nextLine(), input.nextLine());

dob.setDate(input.nextInt(), Month.valueOf(input.next()), input.nextInt());

h.setHeight(input.nextInt(), input.nextInt());

weight = input.nextDouble();

currentYear = input.nextInt();

input.nextLine();

// Construct a HealthProfile class object

HealthProfile hr = new HealthProfile ( name, dob, h, weight, currentYear);

// Display patient 1 info

System.out.printf("First patient%n");

System.out.println("--------------");

hr.displayInfo();

System.out.println();

System.out.println();

// patient 2 info from file

name = new Name(input.nextLine(), input.nextLine());

dob.setDate(input.nextInt(), Month.valueOf(input.next()), input.nextInt());

h.setHeight(input.nextInt(), input.nextInt());

weight = input.nextDouble();

currentYear = input.nextInt();

HealthProfile hr1 = new HealthProfile(name, dob, h, weight, currentYear);

// Display patient 2 info

System.out.printf("Second patient%n");

System.out.println("--------------");

hr1.displayInfo();

}

}

Name: Mohamed Ali, Bin Abdullah Date of birth: 15 Oct 1951 Your weight: 63.5kg Your height: 5 feet 6 inches; equivalent to: 1.68 meter Current year: 2022 Your age: 71 years old Clinic analysis, base on your age: 1. Your maximum heart rate is 149 2. Your minimum target heart rate is 74.50 3. Your maximum target heart rate is 126.65 Your BMI 22.6 Weight category Range Underweight / too low Below 18.5 Healthy range 18.525 Overweight 2530 Obese 3035 Severe Obesity 3540 Morbid Obesity Over 40 Einget-NotepadMohamedAliBinAbdullah15Oct19515663.52022AlanRichardHeng31Dec20056898.82022

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!