I am trying to add another error for the if (student == 1,2,3)
.
And if they input a 0 for the amount of credits they are taking it shows an invalid input message.
Any help on what I am doing wrong?
import javax.swing.*;
import java.text.*;
public class TuitionCost {
public static void main(String[] args) {
int costHours;
int student;
String input;
double a;
double b;
double c;
DecimalFormat dollar = new DecimalFormat("#,##0.00");
JOptionPane.showMessageDialog(null, "OCC Tuition Cost Calculation Program", "Tuition Costs at OCC", JOptionPane.INFORMATION_MESSAGE);
input = JOptionPane.showInputDialog(null, "Are you a:\n1 - College District Residents\n2 - Non-Residents of College District\n3 - Out-of-State and International Students\n\nPlease enter 1, 2 or 3:", "Input", JOptionPane.QUESTION_MESSAGE);
student = Integer.parseInt(input);
if (student == 1) {
input = JOptionPane.showInputDialog(null, "How many credit hours are you taking?", JOptionPane.QUESTION_MESSAGE);
costHours = Integer.parseInt(input);
a = costHours * 76.40;
JOptionPane.showMessageDialog(null, dollar.format(costHours) + " hours at $76.40 per hour yields a tuition of $" + dollar.format(a));
System.exit(0);
}
if (student == 2) {
input = JOptionPane.showInputDialog(null, "How many credit hours are you taking?", JOptionPane.QUESTION_MESSAGE);
costHours = Integer.parseInt(input);
b = costHours * 139.10;
JOptionPane.showMessageDialog(null, dollar.format(costHours) + " hours at $139.10 per hour yields a tuition of $" + dollar.format(b));
System.exit(0);
}
if (student == 3) {
input = JOptionPane.showInputDialog(null, "How many credit hours are you taking?", JOptionPane.QUESTION_MESSAGE);
costHours = Integer.parseInt(input);
c = costHours * 195.15;
JOptionPane.showMessageDialog(null, dollar.format(costHours) + " hours at $195.15 per hour yields a tuition of $" + dollar.format(c));
System.exit(0);
} else {
JOptionPane.showMessageDialog(null, "You must enter a 1, 2, or 3.\nPlease Run the program again.", "Invalid Input", JOptionPane.ERROR_MESSAGE);
}
System.exit(0);
}
}