Answer:
This is the answer in Java (Java is not the same as JavaScript)
import java.util.Scanner;
import static java.lang.System.out;
public class AdmissionPrice {
// Global variables
private static String status;
private static boolean gameDay;
private static boolean hasCoupon;
private static String coupCode;
public static void main(String[] args) {
float cost = 0;
askUser();
cost = getCost(status, gameDay);
if(hasCoupon) {
cost = getDiscount(coupCode, cost);
}
out.print("Your cost is: $" + cost);
}
private static void askUser() {
Scanner scanner = new Scanner(System.in);
out.print("Are you a student or adult (enter s or a)? ");
status = scanner.nextLine();
out.print("Is this for a game today? ");
String gameDayLocal = scanner.nextLine();
gameDay = gameDayLocal.equalsIgnoreCase("yes");
out.print("Do you have a coupon? ");
String hasCouponLocal = scanner.nextLine();
hasCoupon = hasCouponLocal.equalsIgnoreCase("yes");
if(hasCoupon) {
out.print("What is the code? ");
coupCode = scanner.nextLine();
}
}
private static int getCost(String st, boolean gd) {
int cost = 0;
switch(st) {
case "a": {
cost = 10;
break;
}
case "s": {
cost = 6;
break;
}
}
if(gd) {
cost++;
}
return cost;
}
private static float getDiscount(String coup, float c) {
switch(coup) {
case "CHS2021": {
c *= .95;
break;
}
case "CHSVIP": {
c *= .9;
break;
}
}
return c;
}
}
Explanation:
Everything works as intended and the project should have no problem passing! :)