Java Programming Question: How do I write my code below in object oriented progr
ID: 3734837 • Letter: J
Question
Java Programming Question: How do I write my code below in object oriented programming? I am thinking about breaking it up into 5 classes. The first code below is an example of a simple program with object oriented programming, and my code is below that, but I am not sure how to break it up into classes.
MY CODE:
Program Overview: This program calculates the cost of University tuition for one year (2 semesters and 1 summer) for
undergraduate and graduate students (resident, non-resident, and international students) based on various menu options.
Input: type of student (full-time or part-time), number of credits, summer student, number of additional summer
credits, number of rooms for housing (0,1, or 2), meal plan, and a menu option.
Output: cost of University tuition for one year for undergraduate and graduate students (resident, non-resident, and
international students).
*/
import java.util.Scanner;
public class Tuition
{
static Scanner sc = new Scanner (System.in);
public static void main (String [] args)
{
double cost;
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 (); //Call all functions
System.out.println("Cost of University tuition for an undergraduate resident student for one year: $ " + cost);
break;
case '2': cost = UgNonRes ();
System.out.println("Cost of University tuition for an undergraduate non-resident student for one year: $ " + cost);
break;
case '3': cost = UgInt ();
System.out.println("Cost of University tuition for an undergraduate international student for one year: $ " + cost);
break;
case '4': cost = GradRes ();
System.out.println("Cost of University tuition for a graduate resident student for one year: $ " + cost);
break;
case '5': cost = GradNonRes ();
System.out.println("Cost of University tuition for a graduate non-resident student for one year: $ " + cost);
break;
case '6': cost = GradInt ();
System.out.println("Cost of University tuition for a graduate international student for one year: $ " + cost);
break;
case 'Q': System.out.println("Quit");
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(" '1' for the cost of University tuition for an undergraduate resident student for one year");
System.out.println(" '2' for the cost of University tuition for an undergraduate non-resident student for one year");
System.out.println(" '3' for the cost of University tuition for an undergraduate international student for one year");
System.out.println(" '4' for the cost of University tuition for a graduate resident student for one year");
System.out.println(" '5' for the cost of University tuition for a graduate non-resident student for one year");
System.out.println(" '6' for the cost of University tuition for a graduate international student for one year");
System.out.println(" 'Q' to quit the program");
}
public static double UgRes () //Undergraduate resident student method
{
int cred, summercred = 0, room;
double cost = 0.0;
char type, summer, meal;
System.out.println("Enter 'F' for full-time or 'P' for part-time");
type = sc.next().charAt(0);
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
System.out.println("Enter 'S' if student is taking additional summer classes or 'T' if student is not taking additional summer classes");
summer = sc.next().charAt(0);
if (summer == 'S')
{
System.out.println("Enter number of additional summer credits");
summercred = sc.nextInt();
}
System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus");
room = sc.nextInt();
System.out.println("Enter 'M' if student will have a meal plan or 'N' if student will not have a meal plan");
meal = sc.next().charAt(0);
if (type == 'F' && summer == 'S') //Full-time students taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 2400) + ((summercred * 325) + (summercred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550) + ((summercred * 325) + (summercred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 4750 + 2400) + ((summercred * 325) + (summercred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 4750) + ((summercred * 325) + (summercred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 3400 + 2400) + ((summercred * 325) + (summercred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 3400) + ((summercred * 325) + (summercred * 55) + 3400);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 2400) + ((summercred * 325) + (summercred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55)) + ((summercred * 325) + (summercred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750 + 2400) + ((summercred * 325) + (summercred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750) + ((summercred * 325) + (summercred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400 + 2400) + ((summercred * 325) + (summercred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400) + ((summercred * 325) + (summercred * 55) + 3400);
}
}
}
}
if (type == 'F' && summer == 'T') //Full-time students not taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550);
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 3400);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400);
}
}
}
}
if (type == 'P' && summer == 'S') //Part-time students taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 2400) + ((summercred * 325) + (summercred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55)) + ((summercred * 325) + (summercred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750 + 2400) + ((summercred * 325) + (summercred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750) + ((summercred * 325) + (summercred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400 + 2400) + ((summercred * 325) + (summercred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400) + ((summercred * 325) + (summercred * 55) + 3400);
}
}
}
}
if (type == 'P' && summer == 'T') //Part-time students not taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400);
}
}
}
}
return cost;
}
public static double UgNonRes () //Undergraduate non-resident student method
{
int cred, summercred = 0, room;
double cost = 0.0;
char type, summer, meal;
System.out.println("Enter 'F' for full-time or 'P' for part-time");
type = sc.next().charAt(0);
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
System.out.println("Enter 'S' if student is taking additional summer classes or 'T' if student is not taking additional summer classes");
summer = sc.next().charAt(0);
if (summer == 'S')
{
System.out.println("Enter number of additional summer credits");
summercred = sc.nextInt();
}
System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus");
room = sc.nextInt();
System.out.println("Enter 'M' if student will have a meal plan or 'N' if student will not have a meal plan");
meal = sc.next().charAt(0);
if (type == 'F' && summer == 'S') //Full-time students taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 2400) + ((summercred * 475) + (summercred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650) + ((summercred * 475) + (summercred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 4850 + 2400) + ((summercred * 475) + (summercred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 4850) + ((summercred * 475) + (summercred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 3500 + 2400) + ((summercred * 575) + (summercred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 3500) + ((summercred * 475) + (summercred * 65) + 3500);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 2400) + ((summercred * 475) + (summercred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65)) + ((summercred * 475) + (summercred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850 + 2400) + ((summercred * 475) + (summercred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850) + ((summercred * 475) + (summercred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500 + 2400) + ((summercred * 475) + (summercred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500) + ((summercred * 475) + (summercred * 65) + 3500);
}
}
}
}
if (type == 'F' && summer == 'T') //Full-time students not taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650);
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 3500);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500);
}
}
}
}
if (type == 'P' && summer == 'S') //Part-time students taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 2400) + ((summercred * 475) + (summercred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65)) + ((summercred * 475) + (summercred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850 + 2400) + ((summercred * 475) + (summercred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850) + ((summercred * 475) + (summercred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500 + 2400) + ((summercred * 475) + (summercred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500) + ((summercred * 475) + (summercred * 65) + 3500);
}
}
}
}
if (type == 'P' && summer == 'T') //Part-time students not taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500);
}
}
}
}
return cost;
}
public static double UgInt () //Undergraduate international student method
{
int cred, summercred = 0, room;
double cost = 0.0;
char type, summer, meal;
System.out.println("Enter 'F' for full-time or 'P' for part-time");
type = sc.next().charAt(0);
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
System.out.println("Enter 'S' if student is taking additional summer classes or 'T' if student is not taking additional summer classes");
summer = sc.next().charAt(0);
if (summer == 'S')
{
System.out.println("Enter number of additional summer credits");
summercred = sc.nextInt();
}
System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus");
room = sc.nextInt();
System.out.println("Enter 'M' if student will have a meal plan or 'N' if student will not have a meal plan");
meal = sc.next().charAt(0);
if (type == 'F' && summer == 'S') //Full-time students taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 2400) + ((summercred * 625) + (summercred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750) + ((summercred * 625) + (summercred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 4950 + 2400) + ((summercred * 625) + (summercred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 4950) + ((summercred * 625) + (summercred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 3600 + 2400) + ((summercred * 625) + (summercred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 3600) + ((summercred * 625) + (summercred * 75) + 3600);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 2400) + ((summercred * 625) + (summercred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75)) + ((summercred * 625) + (summercred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950 + 2400) + ((summercred * 625) + (summercred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950) + ((summercred * 625) + (summercred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600 + 2400) + ((summercred * 625) + (summercred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600) + ((summercred * 625) + (summercred * 75) + 3600);
}
}
}
}
if (type == 'F' && summer == 'T') //Full-time students not taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750);
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 3600);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600);
}
}
}
}
if (type == 'P' && summer == 'S') //Part-time students taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 2400) + ((summercred * 625) + (summercred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75)) + ((summercred * 625) + (summercred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950 + 2400) + ((summercred * 625) + (summercred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950) + ((summercred * 625) + (summercred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600 + 2400) + ((summercred * 625) + (summercred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600) + ((summercred * 625) + (summercred * 75) + 3600);
}
}
}
}
if (type == 'P' && summer == 'T') //Part-time students not taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600);
}
}
}
}
return cost;
}
public static double GradRes () //Graduate non-resident student method
{
int cred;
double cost = 0.0;
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
cost = 2 * ((cred * 510) + (cred * 110));
return cost;
}
public static double GradNonRes () //Graduate non-resident student method
{
int cred;
double cost = 0.0;
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
cost = 2 * ((cred * 780) + (cred * 145));
return cost;
}
public static double GradInt () //Graduate international student method
{
int cred;
double cost = 0.0;
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
cost = 2 * ((cred * 850) + (cred * 155));
return cost;
}
} //End class
Explanation / Answer
Answer:
Tuition.java:
import java.util.Scanner;
public class Tuition
{
static Scanner sc = new Scanner (System.in);
public static void main (String [] args)
{
double cost;
char option;
menu();
System.out.println("Choose an option");
option = sc.next().charAt(0);
do //do while loop
{
switch (option) //Switch
{
case '1': cost = UG_ResidentStudents.UgRes (); //Call all functions
System.out.println("Cost of University tuition for an undergraduate resident student for one year: $ " + cost);
break;
case '2': cost = UG_NonResidentStudents.UgNonRes ();
System.out.println("Cost of University tuition for an undergraduate non-resident student for one year: $ " + cost);
break;
case '3': cost = UG_InternationalStudents.UgInt ();
System.out.println("Cost of University tuition for an undergraduate international student for one year: $ " + cost);
break;
case '4': cost = Graduates.GradRes ();
System.out.println("Cost of University tuition for a graduate resident student for one year: $ " + cost);
break;
case '5': cost = Graduates.GradNonRes ();
System.out.println("Cost of University tuition for a graduate non-resident student for one year: $ " + cost);
break;
case '6': cost = Graduates.GradInt ();
System.out.println("Cost of University tuition for a graduate international student for one year: $ " + cost);
break;
case 'Q': System.out.println("Quit");
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(" '1' for the cost of University tuition for an undergraduate resident student for one year");
System.out.println(" '2' for the cost of University tuition for an undergraduate non-resident student for one year");
System.out.println(" '3' for the cost of University tuition for an undergraduate international student for one year");
System.out.println(" '4' for the cost of University tuition for a graduate resident student for one year");
System.out.println(" '5' for the cost of University tuition for a graduate non-resident student for one year");
System.out.println(" '6' for the cost of University tuition for a graduate international student for one year");
System.out.println(" 'Q' to quit the program");
}
} //End class
UG_ResidentStudents.java:
import java.util.Scanner;
public class UG_ResidentStudents {
public static double UgRes () //Undergraduate resident student method
{
int cred, summercred = 0, room;
double cost = 0.0;
char type, summer, meal;
Scanner sc = new Scanner(System.in);
System.out.println("Enter 'F' for full-time or 'P' for part-time");
type = sc.next().charAt(0);
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
System.out.println("Enter 'S' if student is taking additional summer classes or 'T' if student is not taking additional summer classes");
summer = sc.next().charAt(0);
if (summer == 'S')
{
System.out.println("Enter number of additional summer credits");
summercred = sc.nextInt();
}
System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus");
room = sc.nextInt();
System.out.println("Enter 'M' if student will have a meal plan or 'N' if student will not have a meal plan");
meal = sc.next().charAt(0);
if (type == 'F' && summer == 'S') //Full-time students taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 2400) + ((summercred * 325) + (summercred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550) + ((summercred * 325) + (summercred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 4750 + 2400) + ((summercred * 325) + (summercred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 4750) + ((summercred * 325) + (summercred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 3400 + 2400) + ((summercred * 325) + (summercred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 3400) + ((summercred * 325) + (summercred * 55) + 3400);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 2400) + ((summercred * 325) + (summercred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55)) + ((summercred * 325) + (summercred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750 + 2400) + ((summercred * 325) + (summercred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750) + ((summercred * 325) + (summercred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400 + 2400) + ((summercred * 325) + (summercred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400) + ((summercred * 325) + (summercred * 55) + 3400);
}
}
}
}
if (type == 'F' && summer == 'T') //Full-time students not taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550);
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + 550 + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + 550 + 3400);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * (4000 + ((cred - 18) * 325) + 550 + ((cred - 18) * 55) + 3400);
}
}
}
}
if (type == 'P' && summer == 'S') //Part-time students taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 2400) + ((summercred * 325) + (summercred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55)) + ((summercred * 325) + (summercred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750 + 2400) + ((summercred * 325) + (summercred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750) + ((summercred * 325) + (summercred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400 + 2400) + ((summercred * 325) + (summercred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400) + ((summercred * 325) + (summercred * 55) + 3400);
}
}
}
}
if (type == 'P' && summer == 'T') //Part-time students not taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 4750);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 325) + (cred * 55) + 3400);
}
}
}
}
return cost;
}
}
UG_NonResidentStudents.java:
import java.util.Scanner;
public class UG_NonResidentStudents {
public static double UgNonRes () //Undergraduate non-resident student method
{
Scanner sc = new Scanner(System.in);
int cred, summercred = 0, room;
double cost = 0.0;
char type, summer, meal;
System.out.println("Enter 'F' for full-time or 'P' for part-time");
type = sc.next().charAt(0);
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
System.out.println("Enter 'S' if student is taking additional summer classes or 'T' if student is not taking additional summer classes");
summer = sc.next().charAt(0);
if (summer == 'S')
{
System.out.println("Enter number of additional summer credits");
summercred = sc.nextInt();
}
System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus");
room = sc.nextInt();
System.out.println("Enter 'M' if student will have a meal plan or 'N' if student will not have a meal plan");
meal = sc.next().charAt(0);
if (type == 'F' && summer == 'S') //Full-time students taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 2400) + ((summercred * 475) + (summercred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650) + ((summercred * 475) + (summercred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 4850 + 2400) + ((summercred * 475) + (summercred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 4850) + ((summercred * 475) + (summercred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 3500 + 2400) + ((summercred * 575) + (summercred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 3500) + ((summercred * 475) + (summercred * 65) + 3500);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 2400) + ((summercred * 475) + (summercred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65)) + ((summercred * 475) + (summercred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850 + 2400) + ((summercred * 475) + (summercred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850) + ((summercred * 475) + (summercred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500 + 2400) + ((summercred * 475) + (summercred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500) + ((summercred * 475) + (summercred * 65) + 3500);
}
}
}
}
if (type == 'F' && summer == 'T') //Full-time students not taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650);
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + 650 + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + 650 + 3500);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * (5850 + ((cred - 18) * 475) + 650 + ((cred - 18) * 65) + 3500);
}
}
}
}
if (type == 'P' && summer == 'S') //Part-time students taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 2400) + ((summercred * 475) + (summercred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65)) + ((summercred * 475) + (summercred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850 + 2400) + ((summercred * 475) + (summercred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850) + ((summercred * 475) + (summercred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500 + 2400) + ((summercred * 475) + (summercred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500) + ((summercred * 475) + (summercred * 65) + 3500);
}
}
}
}
if (type == 'P' && summer == 'T') //Part-time students not taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 4850);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 475) + (cred * 65) + 3500);
}
}
}
}
return cost;
}
}
UG_InternationalStudents:
import java.util.Scanner;
public class UG_InternationalStudents {
public static double UgInt () //Undergraduate international student method
{
Scanner sc = new Scanner(System.in);
int cred, summercred = 0, room;
double cost = 0.0;
char type, summer, meal;
System.out.println("Enter 'F' for full-time or 'P' for part-time");
type = sc.next().charAt(0);
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
System.out.println("Enter 'S' if student is taking additional summer classes or 'T' if student is not taking additional summer classes");
summer = sc.next().charAt(0);
if (summer == 'S')
{
System.out.println("Enter number of additional summer credits");
summercred = sc.nextInt();
}
System.out.println("Enter number of rooms for housing, 1 or 2, or 0 if not living on campus");
room = sc.nextInt();
System.out.println("Enter 'M' if student will have a meal plan or 'N' if student will not have a meal plan");
meal = sc.next().charAt(0);
if (type == 'F' && summer == 'S') //Full-time students taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 2400) + ((summercred * 625) + (summercred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750) + ((summercred * 625) + (summercred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 4950 + 2400) + ((summercred * 625) + (summercred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 4950) + ((summercred * 625) + (summercred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 3600 + 2400) + ((summercred * 625) + (summercred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 3600) + ((summercred * 625) + (summercred * 75) + 3600);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 2400) + ((summercred * 625) + (summercred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75)) + ((summercred * 625) + (summercred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950 + 2400) + ((summercred * 625) + (summercred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950) + ((summercred * 625) + (summercred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600 + 2400) + ((summercred * 625) + (summercred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600) + ((summercred * 625) + (summercred * 75) + 3600);
}
}
}
}
if (type == 'F' && summer == 'T') //Full-time students not taking additional summer classes
{
if (12 <= cred && cred <= 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750);
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + 750 + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + 750 + 3600);
}
}
}
if (cred > 18)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * (7550 + ((cred - 18) * 625) + 750 + ((cred - 18) * 75) + 3600);
}
}
}
}
if (type == 'P' && summer == 'S') //Part-time students taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 2400) + ((summercred * 625) + (summercred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75)) + ((summercred * 625) + (summercred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950 + 2400) + ((summercred * 625) + (summercred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950) + ((summercred * 625) + (summercred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600 + 2400) + ((summercred * 625) + (summercred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600) + ((summercred * 625) + (summercred * 75) + 3600);
}
}
}
}
if (type == 'P' && summer == 'T') //Part-time students not taking additional summer students
{
if (cred < 12)
{
if (room == 0)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75));
}
}
if (room == 1)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 4950);
}
}
if (room == 2)
{
if (meal == 'M')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600 + 2400);
}
if (meal == 'N')
{
cost = 2 * ((cred * 625) + (cred * 75) + 3600);
}
}
}
}
return cost;
}
}
Graduates.java:
import java.util.Scanner;
public class Graduates {
public static Scanner sc = new Scanner(System.in);
public static double GradRes () //Graduate non-resident student method
{
int cred;
double cost = 0.0;
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
cost = 2 * ((cred * 510) + (cred * 110));
return cost;
}
public static double GradNonRes () //Graduate non-resident student method
{
int cred;
double cost = 0.0;
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
cost = 2 * ((cred * 780) + (cred * 145));
return cost;
}
public static double GradInt () //Graduate international student method
{
int cred;
double cost = 0.0;
System.out.println("Enter number of credits per semester");
cred = sc.nextInt();
cost = 2 * ((cred * 850) + (cred * 155));
return cost;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.