Question: Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat
Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario.



import java.util.Scanner;
public class sampleforchegg {
public static void main(String[] args) {
//while loop goes here
Scanner console= new Scanner (System.in);
printAsterisks(); //printing 2 lines of 50 asterisk int waist = inputWaist(); //taking input of waist int height = inputHeight(); //taking input of height String gender = inputGender(); //taking input of gender String message = ""; int minutes = getMinutes(console); printAsterisks(); int ratio = waist_to_height_ratio(waist,height); //Calculating the ratio String s= "y";
if(gender.equalsIgnoreCase("f")) //get the message using the waist to height ration and gender { //open if/else if(ratio = 42 && ratio = 48.01 && ratio 57) message = "You are considered obese."; } //close if/else
else { //open if/else if(ratio = 43 && ratio = 52.01 && ratio 62) message = "You are considered obese."; } //close if/else
display(waist, height, gender, ratio, message, minutes); //print the information
} //closing main
//#1 METHOD- method that prints two lines of asterisks public static void printAsterisks() { //open forloop for(int i = 0; i
//#2 METHOD- function for taking input of the waist in inches public static int inputWaist() { Scanner scan = new Scanner(System.in); //Creating an object of scanner class System.out.print("Please enter your waist measurement, in inches: "); //Printing the appropriate message to the user int waist = scan.nextInt(); //Taking the input System.out.println(); return waist; //Returning the value of waist }
//#3 METHOD- Function for taking the input of height in feet and inches public static int inputHeight() { Scanner scan = new Scanner(System.in); // Creating an object of Scanner class. System.out.print("Please enter your height measurement, in feet and inches (Separate feet and inches by space): "); int height_feet =scan.nextInt(); System.out.println(); int height_inches = scan.nextInt(); return height_feet*12 + height_inches; //converting the feet to inches by multiplying 12 }
//#4 METHOD- Fuction for taking the input of the users gender public static String inputGender() { Scanner scan = new Scanner(System.in); // Creating an object of Scanner class. System.out.print("Please enter your gender, F for female or M for male: "); String gender = scan.next(); System.out.println(); return gender; }
//#5 METHOD= fuction for taking total minutes of exercise in 7 days public static int getMinutes (Scanner console) { int sum=0, minutes; for (int i=1; i
//#6 METHOD- for caculating the ratio of wait/height public static int waist_to_height_ratio(int waist, int height) { double percentage; percentage = (waist*1.0)/(height*1.0) * 100.0; // Converting the integer values of double and calculating the percentage //ROunding the double value to the nearest integer and converting long integer returned be Math.round() int k= (int)Math.round(percentage); return k; //returning the percentage }
// #7 METHOD- for printing out users results public static void display(int waist, int height, String gender, int ratio, String message, int minutes) { System.out.println("Waist = " + waist + " inches"); System.out.println("Height = " + height + " inches"); System.out.println("Gender = " + gender); System.out.println("Waist to Height Ratio = " + ratio + "%"); System.out.println(message); System.out.println("Number of Minutes of Exercise in a Typical Week = " + minutes);
System.out.println("Would you like to perform health calculation of another user(enter Y/N)"); Scanner scan = new Scanner(System.in); // Creating an object of Scanner class. String s=scan.next(); switch(s) { case "y": System.out.println(""); break; default: System.out.println(" Thank you for using health calculator! Good Bye!"); break; } } } //Closes class
For this assignment, you will create a Java program that will evaluate a person's health. The program will ask the user for their waist measurement (in inches), height measurement (in feet and inches), gender and number of minutes of exercise they get in a typical week. After evaluating, the program will print the user's waist measurement (in inches), height measurement (in inches), gender, waist to height ratio (as a percentage, rounded to 2 decimal places), a ratio message, the total number of minutes of exercise they get in a typical week and an exercise message onto the screen. Items will be displayed, as shown below (remember to use -, where appropriate. Example output is shown below in red (note the output shown below is an example, your values will be different). Before asking for the user's waist measurement and, again, before printing the user's measurements, you will print 2 lines containing 50 asterisks per line (you must use a nested for loop to complete this task). After printing one user's waist to height ratio, the program will ask if they would like to calculate another waist to height ratio (this will continue, as long as the user indicates that they would like to perform another calculation). The ratio message that will be displayed is dependent upon the indicated gender and waist to height ratio, as shown below Gender Female Waist to Height Ratio Under 42% 42% to 48% 48.01% to 57% Over 57% Under 43% 43% to 52% 52.01% to 62% Over 62% Ratio Message You are considered underwei You are at a healthy weight! You are considered overweight. You are considered obese You are considered underweight You are at a healthy weight! You are considered overweight You are considered obese Male The exercise message that will be displayed is dependent upon the number of minutes of exercise that the user gets in a typical week. If the user gets under 150 minutes, print the message You are not getting a sufficient amount of exercise in a typical week. Otherwise, print the message You are getting adequate exercise in a typical week This program must make use of a nested if/else statement, a while or do...while loop and a switch This program will make use of 7 methods. The first method will be used to print the lines of asterisks onto the screen. The second method will be used to ask for the waist measurement (in inches). The third method will be used to ask for the height measurement (in feet and inches) and convert this height to total inches (remember, a method can return only a single vale) The fourth method will be used to ask for the user's gender. The fifth method will be used to ask for the typical number of minutes of exercise the user gets each day of the week; this method will perform a cumulative algorithm to calculate the total number of minutes of exercise that the user gets in a typical week. The sixth method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
