A college calculates tuition based on student classifications. Resident undergra
ID: 3804877 • Letter: A
Question
A college calculates tuition based on student classifications. Resident undergraduate students (living in state) pay a set amount per credit for 12 or fewer credits and pay 75% of set amount per credit for all additional credits. Non- resident undergraduate students (living out of state) pay $5000 plus 80% of the set amount for all credits taken. Graduate students pay $9,500 per semester regardless of the number of credits taken.
Complete the code for the Java class named TuitionPayment that includes functionality to compute the tuition amount for each student. You do not know the number of students in advance. Each type of student has their own student code: Resident undergraduate students have student code 1, non-resident undergraduate students have student code 2, and graduate students have student code 3. A template for completing this assignment has been started for you with the NetBeans project posted to CANVAS.
Complete the main method that creates an instance of the TuitionPayment class, and calls the setAmountPerCredit method to set the credit payment to $325.00. The main method should then prompt the user for the student code –“Enter student code (-1 to end): “, validate the input and perform the associated processing for that student code. Your program should allow the user to process students until a student code of -1 has been entered. Use a switch structure to compute each student’s tuition payment, based on the student code. Within the switch, prompt the user (i.e. the bursar) to enter the appropriate facts your program needs to calculate each student’s tuition amount based on that student code, invoke the respective method (defined below) to perform the calculations and return the semester tuition amount for each type of student, and print the returned tuition amount for each student.
Complete the declaration and management of the following five private instance variables: amountPerCredit, to- talTuitionCalculated, numResidentUndergrad, numNonResidentUndergrad, numGraduate.
A setAmountPerCredit method that accepts a defined amount per credit as a parameter. This method stores the parameter value in the amountPerCredit instance variable for later use.
Define a calcResidentUndergradTuition method that accepts the number of credits as input parameter and returns the semester tuition based on resident undergraduate student description as stated above.
Define a calcNonResidentUndergradTuition method that accepts the number of credits as input parameter and returns the semester tuition based on non-resident undergraduate student description as stated above.
Define a calcGraduateTuition method that has no parameters and returns the semester tuition based on the graduate student description as stated above.
Once all students have been processed, the totalTuitionCalculated calculated for all students, and the total number of each type of student processed (i.e. values in the numResidentUndergrad, numNonResidentUndergrad, numGraduate) should be printed. Where should each of the counters be updated in the code? Remember to print the values of these variables once the processing of students is complete.
Explanation / Answer
TutionPayment.java:
import java.util.Scanner;
public class TuitionPayment {
static final int Resident_undergraduate = 1;
static final int non_resident_undergraduate = 2;
static final int graduates = 3;
private double amountPerCredit;
private int totalTuitionCalculated, numResidentUndergrad,
numNonResidentUndergrad, numGraduate;
void setAmountPerCredit(double amountPerCredit) {
this.amountPerCredit = amountPerCredit;
}
double calcResidentUndergradTuition(int credits) {
numResidentUndergrad++;
if (credits <= 12)
return credits * amountPerCredit;
else
return 12 * amountPerCredit + (credits - 12) * 0.75
* amountPerCredit;
}
double calcNonResidentUndergradTuition(int credits) {
numNonResidentUndergrad++;
return 5000 + credits * 0.8 * amountPerCredit;
}
double calcGraduateTuition() {
numGraduate++;
return 9500;
}
public int getTotalTuitionCalculated() {
totalTuitionCalculated = numResidentUndergrad + numNonResidentUndergrad
+ numGraduate;
return totalTuitionCalculated;
}
public int getNumResidentUndergrad() {
return numResidentUndergrad;
}
public void setNumResidentUndergrad(int numResidentUndergrad) {
this.numResidentUndergrad = numResidentUndergrad;
}
public int getNumNonResidentUndergrad() {
return numNonResidentUndergrad;
}
public void setNumNonResidentUndergrad(int numNonResidentUndergrad) {
this.numNonResidentUndergrad = numNonResidentUndergrad;
}
public int getNumGraduate() {
return numGraduate;
}
public void setNumGraduate(int numGraduate) {
this.numGraduate = numGraduate;
}
public static void main(String[] args) {
TuitionPayment tuitionPayment = new TuitionPayment();
tuitionPayment.setAmountPerCredit(325);
Scanner s = new Scanner(System.in);
int studentCode = 0;
while (studentCode != -1) {
System.out.println("Enter student code(-1 for exit): ");
studentCode = s.nextInt();
if (studentCode < 1 || studentCode > 3) {
if (studentCode != -1) {
System.out.println("Invalid Input.");
}
} else {
switch (studentCode) {
case 1:
case 2:
System.out.println("Enter total credits");
int credits = s.nextInt();
if (studentCode == 1)
System.out.println("Semester fees: "
+ tuitionPayment
.calcResidentUndergradTuition(credits)
+ "$");
if (studentCode == 2)
System.out
.println("Semester fees: "
+ tuitionPayment
.calcNonResidentUndergradTuition(credits)
+ "$");
break;
case 3:
System.out.println("Semester fees: "
+ tuitionPayment.calcGraduateTuition() + "$");
break;
}
}
}
System.out.println("numResidentUndergrad: "
+ tuitionPayment.getNumResidentUndergrad());
System.out.println("numNonResidentUndergrad: "
+ tuitionPayment.getNumNonResidentUndergrad());
System.out.println("numGraduate: " + tuitionPayment.getNumGraduate());
System.out.println("totalTuitionCalculated: "
+ tuitionPayment.getTotalTuitionCalculated());
s.close();
}
}
Sample Output:
Enter student code(-1 for exit):
1
Enter total credits
12
Semester fees: 3900.0$
Enter student code(-1 for exit):
2
Enter total credits
18
Semester fees: 9680.0$
Enter student code(-1 for exit):
3
Semester fees: 9500.0$
Enter student code(-1 for exit):
-2
Invalid Input.
Enter student code(-1 for exit):
-1
numResidentUndergrad: 1
numNonResidentUndergrad: 1
numGraduate: 1
totalTuitionCalculated: 3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.