Question: Project 2 Java Program - Need Help on this Assignment - Instructions Below. NEED HELP ON PART THREE ONLY. I have part 1 and 2,

Project 2 Java Program - Need Help on this Assignment - Instructions Below. NEED HELP ON PART THREE ONLY. I have part 1 and 2, and the code is listed below as well. Part 1 is BMI Class Part 2 is BMITest Class Part 3 is BMIProgram Class Each part has been separated out by class names.

INSTRUCTIONS BELOW:

Purpose: Using instantiable classes, Object Lists, Serialization of objects to a file

Topic: To Your Health company would like the ability to calculate a customers Body Mass Index (BMI). Since their customers are from various backgrounds, they need the ability to enter their height and weight in metric or standard measurements. For metric, height will be entered in centimeters and weight in kilograms. For standard, height will be entered in inches and weight in pounds.

  • This project will contain three classes, one for creating BMI objects, one to test the features of the class, and one to provide the console application (interface)
    • First create a classed called BMI, (NO main method)
      • Code instance variables (does not have a static modifier) of integer type named weight, height, and option; String variables for patient first and last names
      • Code a default constructor that sets weight to 70 kg, height to 170 cm and option to 1 (metric), and your choice of first and last names
      • Code a parameterized constructor that accepts the option, weight, height, first name, last name
      • Code getters and setters for each field
        • In setters for weight and height, validate for > 0, if not, set to default values based on the option
        • In setters for first and last name, validate for not empty, set to default values
      • Code a method named calcBMI that calculates and returns the BMI based on the option (metric or standard research the web for formulas)
      • Code a toString override method that returns the data from the object in the following format: BMI is 99.99 and is consider XXXXXXXXXXXX. Be sure to use the calcBMI method to get the BMI value.
        • Sample calculations:
          • Metric: 70 kg and 170 cm should be 24.20
          • Standard: 170 lbs and 70 inches should be 24.40
          • Example: BMI is 24.20 and is consider Normal
          • Refer to the web to get the BMI categories
    • Second, create a another class called BMITest (with a main method)
      • Be sure to test all parts of your class (both constructors, getters, setters, methods)
      • Hard code the values necessary to test. No need to prompt user.
    • Third, create a class called BMIProgram (with a main method)
      • Once your instantiable class (BMI) has been coded and tested thoroughly (BMITest), you can create a user interface program that will use it.
      • Create and instantiate a static global List that will be used to hold BMI objects
      • Use a menu-driven approach (Option 1 Metric; Option 2 Standard; Option 3 Exit)
        • Prompt for weight and height based on option chosen (be sure to use Try/Catch)
      • Construct a BMI object with the values entered, or default values if not valid
      • Display the results of the entered BMI data (use the toString method from your BMI class)
      • Ask the user if they want to write the BMI data to the file. If yes, add the object to the BMI List, then return to Menu. If not, return to Menu.
      • At Exit, we need to take the objects in the list and serialize them to the file. The file will be over-written with the objects in the current list.
        • Create and open an output file stream
        • Serialize the list to the file
        • Close the file when done

Source Code:

BMI.java: (THIS SECTION OF CODE IS PART ONE)

import java.text.DecimalFormat; public class BMI { private int weight; private int height; private int option; private String firstName; private String lastName; /** * Default constructor * @param weight * @param height * @param option * @param firstName * @param lastName */ public BMI() { this.weight = 70; this.height = 170; this.option = 1; this.firstName = "Default First Name"; this.lastName = "Default Last Name"; } /** * Parameterized constructor * @param weight * @param height * @param option * @param firstName * @param lastName */ public BMI(int weight, int height, int option, String firstName, String lastName) { this.weight = weight; this.height = height; this.option = option; this.firstName = firstName; this.lastName = lastName; } /** * @param weight */ public void setWeight(int weight) { if(this.weight > 0) { this.weight = weight; } } /** * @param height */ public void setHeight(int height) { if(this.height > 0) { this.height = height; } } /** * @param option */ public void setOption(int option) { this.option = option; } /** * @param firstName */ public void setFirstName(String firstName) { if(!this.firstName.equalsIgnoreCase("")) { this.firstName = firstName; } } /** * @param lastName */ public void setLastName(String lastName) { if(!this.lastName.equalsIgnoreCase("")) { this.lastName = lastName; } } /** * @return the weight */ public int getWeight() { return weight; } /** * @return the height */ public int getHeight() { return height; } /** * @return the option */ public int getOption() { return option; } /** * @return the firstName */ public String getFirstName() { return firstName; } /** * @return the lastName */ public String getLastName() { return lastName; } /** * @return BMI */ public double calcBMI() { if(option == 1) { double heightInMeter = (double)height / 100; return (double) weight / (double)(heightInMeter * heightInMeter); }else { return ((double)(weight * 703) / (double)(height * height)); } } public String bmiString() { double bmi = calcBMI(); // check range if(bmi < 18.5) return "Underweight"; else if(bmi < 25) return "Normal"; else if(bmi < 30) return "Overweight"; else return "Obese"; } @Override public String toString() { DecimalFormat df2 = new DecimalFormat("0.00"); return "BMI is " + df2.format(calcBMI()) + " and is consider " + bmiString(); } } 

BMITest.java: (THIS SECTION OF CODE IS PART TWO)

public class BMITest { public static void main(String[] args) { // instantiate the BMI class using parameterized constructor BMI bmi1 = new BMI(70,170,1,"Lora","No"); System.out.println(bmi1.toString()); // instantiate the BMI class using parameterized constructor BMI bmi2 = new BMI(170,70,2,"John","Kennedy"); System.out.println(bmi2.toString()); // instantiate the BMI class using default constructor BMI bmi3 = new BMI(); System.out.println(" "+bmi3.getFirstName()); System.out.println(bmi3.getLastName()); System.out.println(bmi3.getWeight()); System.out.println(bmi3.getHeight()); System.out.println(bmi3.getOption()); System.out.println(bmi3.toString()); // set the values using setter bmi3.setFirstName("Jammiee"); bmi3.setLastName("Lanister"); bmi3.setWeight(40); bmi3.setHeight(80); bmi3.setOption(2); // print the result System.out.println(" "+bmi3.getFirstName()); System.out.println(bmi3.getLastName()); System.out.println(bmi3.getWeight()); System.out.println(bmi3.getHeight()); System.out.println(bmi3.getOption()); System.out.println(bmi3.toString()); } }

BMIProgram.java: (THIS SECTION OF CODE IS PART THREE)

Need part three of the Source Code here for this program. Class name is BMIProgram as instructed above.

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!