36.6k views
20 votes
In this project, you will create a Java program that asks a customer at a clothing store for his waist measurement. Based on his response, you will tell him his pant size is small, medium, or large. You will write this code twice, once using a switch-case statement and once using nested if statements.

( PLEASE HELP, THIS IS MAKING ACTUAL CODE THEY NEVER TAUGHT ME HOW TO CODE SO I DONT KNOW HOW TO, THE CODE DOESN'T NEED TO BE RIGHT IT JUST NEEDS TO LOOK LIKE IT )

User Koropok
by
4.8k points

1 Answer

0 votes
import java.util.Scanner;

public class WaistSize {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("What is the measurement of your waist in inches?");
int waistSize = input.nextInt();

String sizeGuideA = sizeGuide1(waistSize);
String sizeGuideB = sizeGuide2(waistSize);

System.out.println("Nested If Statements return: " + sizeGuideA);
System.out.println("Switch-Case Statements return: " + sizeGuideB);

}
public static String sizeGuide1(int n) {
String size = "null";

if(n <= 25) {
return size = "Extra Small";
}

if(n > 25 && n <= 28) {
return size = "Small";
}

if(n > 28 && n <= 30) {
return size = "Medium";
}

if(n > 30 && n <= 32) {
return size = "Large";
}
else {
return "Error";
}
}

public static String sizeGuide2(int n) {
String size = "null";

switch(n) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
size = "Extra Small";
size = "Extra Small";
break;
case 26:
case 27:
case 28:
size = "Small";
break;
case 29:
case 30:
size = "Medium";
break;
case 31:
case 32:
size = "Large";
break;


}

return size;
}
}
User Mizuki
by
5.3k points