I was given a homework assignment that no matter how hard I try (searching Google, reading the textbooks, etc.) I cannot figure out how to properly nest these statements.
The Fair Grounds Ride Company has been having problems with people that do not meet height requirements getting on rides they should not be on. They need you to write a program to help with this problem. Upon entering the park each customer will get a wrist band of a certain color to indicate which rides they can go on.
If the customer is 36 inches tall or less they will receive a red band and be allowed to ride only slow rides like Turtle’s Slowing Spinning Shell.
If they are between 36 and 54 inches they will receive a yellow band and be allowed to ride moderately fast rides like Rabbit’s Bouncy Easter Egg.
If they are 54 to 80 inches tall they will receive a green band and be allowed to ride exciting rides such as Hindenburg: Jump for Your Life.
If they are over 80 inches tall they will receive no band as they are too tall to ride anything without hitting their head on something so they can just hang out in the Hall of Industry which is perfectly safe for everybody.
import java.util.Scanner;
public class Exercise4_K {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean moreRiders = true;
String bandColor = "";
while (moreRiders) {
System.out.println("Please enter height in inches (or 0 to exit)");
int height = scanner.nextInt();
if (height == 0) {
System.out.println("bye bye");
moreRiders = false;
} else {
if (height > 80) {
bandColor = "Sorry, too tall";
} else if (height <= 36) {
bandColor = "red";
} else if (height <= 80) {
bandColor = "yellow";
} else if (height >= 54){
bandColor = "green";
System.out.println("")
}
}
}
}
}
}
Write a program that will accept a whole number of inches entered by the fair entrance gatekeeper and then print out the appropriate band color or “no band” as per the rules above.
Aucun commentaire:
Enregistrer un commentaire