k48pxt.jpg
here is instruction and here are code I wrote. it runs and produce right result but I am not so sure this is how instruction is asking me to
write the code. could you verify and see if I did things right here? any pointers are appreciated.
Class HealthProfile
import javax.swing.JOptionPane; public class HealthProfile { String fName; String lName; String gender; int bDayMonth; int bDayDay; int bDayYear; int age; double height; double weight; double BMI; String inputString; String inputString1; public HealthProfile() { } public void setFirstName(String fN) { fName = fN; } public void setLastName(String lN) { lName = lN; } public void setGender(String gen) { gender = gen; } public void setBirthMonth(int bMonth) { bDayMonth = bMonth; } public void setBirthDay(int bDay) { bDayDay = bDay; } public void setBirthYear(int bYear) { bDayYear = bYear; } //get patient's first name public String getFirstName() { return fName; } //get patient's last name public String getLastName() { return lName; } //get patient's gender public String getGender() { return gender; } //get patient's month of date of birth public int getBirthMonth() { return bDayMonth; } //get patient's day of date of birth public int getBirthDay() { return bDayDay; } //get patient's year of date of birth public int getBirthYear() { return bDayYear; } //get patient's height in inches and weight in pounds public void display() { inputString = JOptionPane.showInputDialog("What is patient's height in inches?"); height = Double.parseDouble(inputString); inputString1 = JOptionPane.showInputDialog("What is patient's weight in pounds?"); weight = Double.parseDouble(inputString1); } //calculate patient's BMI public void calcBMI() { BMI = (weight*703)/(height*height); } //calculate patient's age public void calcAge() { age = 2013-bDayYear; } }
Project7 Application
import javax.swing.JOptionPane; import java.text.DecimalFormat; public class Project7 { public static void main(String[] args) { String inputString; //declare identifier for HealthProfile Objoect HealthProfile patient1; //create HealthProfile object by calling its constructor patient1 = new HealthProfile(); //input patient's first name patient1.setFirstName(inputString = JOptionPane.showInputDialog("What is patient's first name?")); //input patient's first name patient1.setLastName(inputString = JOptionPane.showInputDialog("What is patient's last name?")); //input patient's gender patient1.setGender(inputString = JOptionPane.showInputDialog("What is patient's gender?")); //input String bMonth = JOptionPane.showInputDialog("What is month of patient's birthday?"); String bDay = JOptionPane.showInputDialog("What is day of patient's birthday?"); String bYear = JOptionPane.showInputDialog("What is year of patient's birthday?"); String fName = patient1.getFirstName(); String lName = patient1.getLastName(); String gender = patient1.getGender(); patient1.setBirthMonth(Integer.parseInt(bMonth)); patient1.setBirthDay(Integer.parseInt(bDay)); patient1.setBirthYear(Integer.parseInt(bYear)); patient1.calcAge(); patient1.display(); //call HealthProfile to get height and weight patient1.calcBMI(); //call HealthProfile to calculate BMI DecimalFormat formatter = new DecimalFormat("#0.0"); //print out the result System.out.println("Patient First Name: " + patient1.getFirstName() + "\n" + "Patient Last Name: " + patient1.getLastName() + "\n" + "Gender: " + patient1.getGender() + "\n" + "Age: " + patient1.age + "\n" + "Weight in pounds: " + patient1.weight + "\n" + "BMI: " + formatter.format(patient1.BMI) + "\n" + "\n" + "BMI VALUES\n" + "Underweight: less than 18.5\n" + "Normal: between 18.5 and 24.9\n" + "Overweight: between 25 and 29.9\n" + "Obese: 30 or greater"); } }