Please do this programming activity using the selection statement.
Write a Java program that calculates the total amount due of a student depending on the plan selected and total number of units. To calculate the tuition fee, the cost per unit is 500 pesos. The total miscellaneous fee of all students is 2,000 pesos and other fees costs 378.50 pesos. The following are the types of payment: (a) For cash payment, the total amount due includes the tuition fees, miscellaneous and other fees; (b) Plan A, the total amount due includes he tuition fees, miscellaneous fee, other fees, and additional installment fee of 1,500 pesos; (c)Plan B, the total amount due includes he tuition fees, miscellaneous fee, other fees, and additional installment fee of 2,000 pesos. The program accepts the total units and payment type. The program should print the total tuition fees, miscellaneous fees, other fees, installment fee (if applicable), and total amount due.
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
double costPerUnit = 500;
double miscellaneousFeeOfAllStudents = 2000;
double otherFees = 378.5;
double totalTuition;
double miscellaneous;
double other;
double totalAmountDue;
Scanner in = new Scanner(System.in);
int totalUnits = in.nextInt();
totalTuition = totalUnits * costPerUnit;
miscellaneous = miscellaneousFeeOfAllStudents;
other = otherFees * totalUnits;
char ch = (char) System.in.read();
switch (ch) {
case 'a' -> {
totalAmountDue = totalTuition + miscellaneous + other;
System.out.printf("%.2f, %.2f, %.2f, %.2f", totalTuition, miscellaneous, other, totalAmountDue);
}
case 'b' -> {
totalAmountDue = totalTuition + miscellaneous + other + 1500;
System.out.printf("%.2f, %.2f, %.2f, 1500, %.2f", totalTuition, miscellaneous, other, totalAmountDue);
}
case 'c' -> {
totalAmountDue = totalTuition + miscellaneous + other + 2000;
System.out.printf("%.2f, %.2f, %.2f, 2000, %.2f", totalTuition, miscellaneous, other, totalAmountDue);
}
default -> System.out.println("Error input");
}
}
}
Comments
Leave a comment