Question: Java Programming Question. I am writing a menu program that calculates the cost of attendance for undergraduate and graduate students (resident, non resident, international). In

Java Programming Question. I am writing a menu program that calculates the cost of attendance for undergraduate and graduate students (resident, non resident, international). In the switch part, I keep getting error messages, saying "cannot find symbol", which I indicated in my code below. How can this be fixed?

import java.util.Scanner; public class Tuition { static Scanner sc = new Scanner (System.in); public static void main (String [] args) { char option; menu(); System.out.println("Choose an option"); option = sc.next().charAt(0); do //do while loop { switch (option) //Switch { case '1': cost = UgRes (cost); //Error - cannot find symbol cost System.out.println("the cost of University attendance for an undergraduate resident student for one year: $ " + cost); break; case '2': cost = UgNonRes (cost); //Error - cannot find symbol cost System.out.println("the cost of University attendance for an undergraduate non-resident student for one year: $ " + cost); break; case '3': cost = UgInt (cost); //Error - cannot find symbol cost System.out.println("the cost of University attendance for an undergraduate international student for one year: $ " + cost); break; case '4': cost = GradRes (cost); //Error - cannot find symbol cost System.out.println("the cost of University attendance for a graduate resident student for one year: $ " + cost); break; case '5': cost = GradNonRes (cost); //Error - cannot find symbol cost System.out.println("the cost of University attendance for a graduate non-resident student for one year: $ " + cost); break; case '6': cost = GradInt (cost); //Error - cannot find symbol cost System.out.println("the cost of University attendance for a graduate international student for one year: $ " + cost); break; } System.out.println("Choose an option"); option = sc.next().charAt(0); } while (option != 'Q');

} //End main method

public static void menu() { System.out.println(" \t '1' for the cost of University attendance for an undergraduate resident student for one year"); System.out.println(" \t '2' for the cost of University attendance for an undergraduate non-resident student for one year"); System.out.println(" \t '3' for the cost of University attendance for an undergraduate international student for one year"); System.out.println(" \t '4' for the cost of University attendance for a graduate resident student for one year"); System.out.println(" \t '5' for the cost of University attendance for a graduate non-resident student for one year"); System.out.println(" \t '6' for the cost of University attendance for a graduate international student for one year"); System.out.println(" \t 'Q' to quit the program"); }

public static double UgRes (double cost) //Undergraduate resident student method { int cred, room; char type; System.out.println("Enter 'F' for full-time, 'P' for part-time, or 'S' for summer student"); type = sc.next().charAt(0); System.out.println("Enter number of credits per semester"); cred = sc.nextInt(); System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus"); room = sc.nextInt(); if (type == 'F') { if (12 <= cred && cred <= 18) { if (room == 0) { cost = 2 * (4000 + 550); } if (room == 1) { cost = 2 * (4000 + 550 + 4750 + 2400); } if (room == 2) { cost = 2 * (4000 + 550 + 3400 + 2400); } } if (cred > 18) { if (room == 0) { cost = 2 *(4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55)); } if (room == 1) { cost = 2 *(4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750 + 2400); } if (room == 2) { cost = 2 *(4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400 + 2400); } } } if (type == 'P' || type == 'S') { if (cred < 12) { if (room == 0) { cost = 2 * ((cred * 325) + (cred * 55)); } if (room == 1) { cost = 2 * ((cred * 325) + (cred * 55) + 4750 + 2400); } if (room == 2) { cost = 2 * ((cred * 325) + (cred * 55) + 3400 + 2400); } } } return cost; }

public static double UgNonRes (double cost) //Undergraduate non-resident student method { int cred, room; char type; System.out.println("Enter 'F' for full-time, 'P' for part-time, or 'S' for summer student"); type = sc.next().charAt(0); System.out.println("Enter number of credits per semester"); cred = sc.nextInt(); System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus"); room = sc.nextInt(); if (type == 'F') { if (12 <= cred && cred <= 18) { if (room == 0) { cost = 2 * (5850 + 650); } if (room == 1) { cost = 2 * (5850 + 650 + 4850 + 2400); } if (room == 2) { cost = 2 * (5850 + 650 + 3500 + 2400); } } if (cred > 18) { if (room == 0) { cost = 2 *(5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65)); } if (room == 1) { cost = 2 *(5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850 + 2400); } if (room == 2) { cost = 2 *(5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500 + 2400); } } } if (type == 'P' || type == 'S') { if (cred < 12) { if (room == 0) { cost = 2 * ((cred * 475) + (cred * 65)); } if (room == 1) { cost = 2 * ((cred * 475) + (cred * 65) + 4850 + 2400); } if (room == 2) { cost = 2 * ((cred * 475) + (cred * 65) + 3500 + 2400); } } } return cost; }

public static void UgInt (double cost) //Undergraduate international student method { int cred, room; char type; System.out.println("Enter 'F' for full-time, 'P' for part-time, or 'S' for summer student"); type = sc.next().charAt(0); System.out.println("Enter number of credits per semester"); cred = sc.nextInt(); System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus"); room = sc.nextInt(); if (type == 'F') { if (12 <= cred && cred <= 18) { if (room == 0) { cost = 2 * (7550 + 750); } if (room == 1) { cost = 2 * (7550 + 750 + 4950 + 2400); } if (room == 2) { cost = 2 * (7550 + 750 + 3600 + 2400); } } if (cred > 18) { if (room == 0) { cost = 2 *(7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75)); } if (room == 1) { cost = 2 *(7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950 + 2400); } if (room == 2) { cost = 2 *(7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600 + 2400); } } } if (type == 'P' || type == 'S') { if (cred < 12) { if (room == 0) { cost = 2 * ((cred * 625) + (cred * 75)); } if (room == 1) { cost = 2 * ((cred * 625) + (cred * 75) + 4950 + 2400); } if (room == 2) { cost = 2 * ((cred * 625) + (cred * 75) + 3600 + 2400); } } } return cost; }

public static double GradRes (double cost) //Graduate resident student method { int cred; System.out.println("Enter number of credits per semester"); cred = sc.nextInt(); cost = 2 * ((cred * 510) + (cred * 110)); return cost; } public static double GradNonRes (double cost) //Graduate non-resident student method { int cred; System.out.println("Enter number of credits per semester"); cred = sc.nextInt(); cost = 2 * ((cred * 780) + (cred * 145)); return cost; } public static double GradInt (double cost) //Graduate international student method { int cred; System.out.println("Enter number of credits per semester"); cred = sc.nextInt(); cost = 2 * ((cred * 850) + (cred * 155)); return cost; } } //End class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!