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)
message = "You are considered underweight.";
else if(ratio >= 42 && ratio <= 48)
message = "You are at a healthy weight!";
else if(ratio >= 48.01 && ratio <= 57)
message = "You are considered overweight.";
else if(ratio > 57)
message = "You are considered obese.";
} //close if/else
else
{ //open if/else
if(ratio < 43)
message = "You are considered underweight.";
else if(ratio >= 43 && ratio <= 52)
message = "You are at a healthy weight!";
else if(ratio >= 52.01 && ratio <= 62)
message = "You are considered overweight.";
else if(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; i++)
{
for(int j = 0; j < 50; j++)
{
System.out.print("*");
}
System.out.println();
}
} //closing forloop
//#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<=7; i++)
{ System.out.print("Please enter the typical number of minutes of
exercise you get on day" + i + " of each week: ");
sum = sum + console.nextInt();
}
minutes = sum;
return minutes;
}
//#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
Hi please find the modified program below:
import java.util.Scanner;
public class sampleforHomeworkLib {
public static void main(String[] args) {
//while loop goes here
Scanner console= new Scanner (System.in);
String s= "y";
do
{
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
if(gender.equalsIgnoreCase("f")) //get the message using the
waist to height ration and gender
{ //open if/else
if(ratio < 42)
message = "You are considered underweight.";
else if(ratio >= 42 && ratio <= 48)
message = "You are at a healthy weight!";
else if(ratio >= 48.01 && ratio <= 57)
message = "You are considered overweight.";
else if(ratio > 57)
message = "You are considered obese.";
} //close if/else
else
{ //open if/else
if(ratio < 43)
message = "You are considered underweight.";
else if(ratio >= 43 && ratio <= 52)
message = "You are at a healthy weight!";
else if(ratio >= 52.01 && ratio <= 62)
message = "You are considered overweight.";
else if(ratio > 62)
message = "You are considered obese.";
} //close if/else
display(waist, height, gender, ratio, message, minutes); //print
the information
System.out.println("Would you like to perform calculations for
another persion (enter y or n)");
s=console.next();
}while (s.equalsIgnoreCase("y"));
System.out.println(" Thank you for using health calculator! Good
Bye!");
} //closing main
//#1 METHOD- method that prints two lines of asterisks
public static void printAsterisks()
{ //open forloop
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 50; j++)
{
System.out.print("*");
}
System.out.println();
}
} //closing forloop
//#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<=7; i++)
{ System.out.print("Please enter the typical number of minutes of
exercise you get on day" + i + " of each week: ");
sum = sum + console.nextInt();
}
minutes = sum;
return minutes;
}
//#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
Output:


Having trouble with the do while/while loop and the switch statement. I got some of the...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
Hello, can someone please fix my code? It runs perfect but I'm having trouble with the index for the incorrect answer array; please run some tests to ensure the code runs properly, thank you! Here is the code: ___________________________________________________________________________________________________________________________ import java.util.Scanner; public class DriverTest{ final static int QuestionTotal = 10; public static void main(String[] args){ // scanner and answer key Scanner scan = new Scanner(System.in); final char[] answers = {'A', 'B', 'C',...
I have spent so much time on this and I am having trouble getting all the methods to work together correctly to run the code right, and I am not sure what is wrong with it. /* You will recreate one or two versions of the logic game shown in the Algorithms movie and you will ask which one the user would like to play. Upon completion of the game, display who won and ask if they would like to...
Let's fix the displayMenu() method! First, edit the method to do the following: We want to also allow the user to quit. Include a "Quit" option in the print statements! Have it get the user input from within the method itself and return an int based on the user's choice. (Make sure to also edit the method header and how it is called back in the main() method!) What is the method's return type now? ...
In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...
I have already finished most of this assignment. I just need some help with the canMove and main methods; pseudocode is also acceptable. Also, the programming language is java. Crickets and Grasshoppers is a simple two player game played on a strip of n spaces. Each space can be empty or have a piece. The first player plays as the cricket pieces and the other plays as grasshoppers and the turns alternate. We’ll represent crickets as C and grasshoppers as...
I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...
Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }
I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...
I don't really understand how to make the scores show up and how to make it start over. I honestly only half understand the things I've used to piece this together to make this work so far. but this is what I was asked to do..... read a user's first and last name read three integer scores, calculate the total and average determine the letter grade based on the following criteria - Average 90-100 grade is A, 80-89.99 grade is...