Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Ideal Weight Write a program to compute the ideal weight for both males and fema

ID: 3664031 • Letter: I

Question

Ideal Weight Write a program to compute the ideal weight for both males and females. According to one study, the ideal weight for a female is 100 pounds plus 5 pounds for each inch in height over 5 feet. For example, the ideal weight for a female who is 5'3" would be 100 + 15 = 115 pounds. For a male the ideal weight is 106 pounds plus 6 pounds for each inch in height over 5 feet. For example, the ideal weight for a male who is 6'2" would be 106 + 14*6 =190 pounds. Your program should ask the user to enter his/her height in feet and inches (both as integers—so a person 5'3" would enter the 5 and the 3). It should then compute and print both the ideal weight for a female and the ideal weight for a male. The general outline of your main function would be as follows: Declare your variables (think about what variables you need—you need to input two pieces of information (what?), then you need some variables for your calculations (see the following steps) Get the input (height in feet and inches) from the user Compute the total number of inches of height (convert feet and inches to total inches) Compute the ideal weight for a female and the ideal weight for a male (here you basically convert the "word" description above to assignment statements) Print the answers Plan your program, then type it in, compile and run it. Be sure it gives correct answers. Enhance the Program a Bit The weight program would be a bit nicer if it didn't just give one number as the ideal weight for each sex. Generally a person's weight is okay if it is within about 15% of the ideal. Add to your program so that in addition to its current output it prints an okay range for each sex—the range is from the ideal weight minus 15% to the ideal weight plus 15%. You may do this by introducing new variables and assignment statements OR directly within your print statements.

Explanation / Answer

Method-1


public class IdealWeight
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
int IdealWeight = 0;
int feet = 0;
int inches = 0;
String male = "male";
String female = "female";
System.out.println ("Please enter your gender:");
String gender = scan.nextLine();
System.out.println ("Please enter feet: ");
feet = scan.nextInt();
System.out.println ("Please enter inches: ");
inches = scan.nextInt();
int additionalInches = 0;
if ( feet > 5 )
{
additionalInches = ((feet - 5) * 12) * 6;
}
if (gender.equalsIgnoreCase("male") || (gender.equalsIgnoreCase("m")))
{
if(feet < 5)
{
IdealWeight = -1;
}
else
{
IdealWeight = 106 + (inches * 6) + additionalInches;
}
}
else if (gender.equalsIgnoreCase("female") || (gender.equalsIgnoreCase("f")))
{
if(feet < 5){
IdealWeight = -1;
}
else
{
IdealWeight = 100 + (inches * 5) + additionalInches;
}
}
if(IdealWeight == -1)
{
System.out.println("Below Ideal Level! ");
}
else
{
System.out.println("Ideal weight: " + IdealWeight + " ");
}
}
}

Method-2

public class IdealWeight
{
public static void main (String[] args)
{
int feet, inches, totalInches;
int femaleWeight, maleWeight;
Scanner scan = new Scanner( System.in );
System.out.println( "This program will calculate the ideal weight for both a male and a female given the height in feet and inches...");
System.out.print("Enter the height in feet: ");
feet = scan.nextInt();
System.out.print("Enter the height in inches: ");
inches = scan.nextInt();
System.out.println("You entered a height of " + feet + "' " + inches + """);
totalInches = feet*12 + inches;
femaleWeight = 100 + (totalInches - 60)*5;
maleWeight = 106 + (totalInches - 60)*6;
System.out.println("The ideal weight for a female is " + femaleWeight + " pounds.");
System.out.println("The ideal weight for a male is " + maleWeight + " pounds.");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote