Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming Question: I am trying to convert my original code into object programming language using objects and constructors and I am having trouble. My

Java Programming Question: I am trying to convert my original code into object programming language using objects and constructors and I am having trouble. My my new code with many errors is listed below.

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'); Undergrad c = new Undergrad (cred, summercred, room, type, summer, meal); //Object c is created and the constructor Undergrad is invoked. c.UgRes(); //Methods called c.UgNonRes(); c.UgInt(); Grad d = new Grad (cred, summercred, room, type, summer, meal); //Object d is created and the constructor Undergrad is invoked. d.GradRes(); //Methods called d.GradNonRes(); d.GradInt(); } //End main method public static void menu() { System.out.println(" \t '1' for the cost of University tuition for an undergraduate resident student for one year"); System.out.println(" \t '2' for the cost of University tuition for an undergraduate non-resident student for one year"); System.out.println(" \t '3' for the cost of University tuition for an undergraduate international student for one year"); System.out.println(" \t '4' for the cost of University tuition for a graduate resident student for one year"); System.out.println(" \t '5' for the cost of University tuition for a graduate non-resident student for one year"); System.out.println(" \t '6' for the cost of University tuition for a graduate international student for one year"); System.out.println(" \t 'Q' to quit the program"); } } //End class

public class Undergrad { int cred, summercred = 0, room; //Instance variables char type, summer, meal; public Undergrad (int cred, int summercred, int room, char type, char summer, char meal) //Constructor { this.cred = cred; this.summercred = summercred; this.room = room; this.type = type; this.summer = summer; this.meal = meal; } public 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 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 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; } } //end class

public class Grad { int cred, summercred = 0, room; //Instance variables char type, summer, meal; public Grad (int cred, int summercred, int room, char type, char summer, char meal) //Constructor { this.cred = cred; this.summercred = summercred; this.room = room; this.type = type; this.summer = summer; this.meal = meal; } public 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 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 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions