Skip to content

Instantly share code, notes, and snippets.

@kmb385
Created February 22, 2014 21:26
Show Gist options
  • Save kmb385/9162659 to your computer and use it in GitHub Desktop.
Save kmb385/9162659 to your computer and use it in GitHub Desktop.
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class TuitionCost {
public static void main(String[] args) {
int costHours;
int student;
String input;
double a;
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);
double[] rates = {76.40,139.10,195.15};
student = Integer.parseInt(input);
if(student > 0 && student < 4){
input = JOptionPane.showInputDialog(null, "How many credit hours are you taking?", JOptionPane.QUESTION_MESSAGE);
costHours = Integer.parseInt(input);
if(costHours != 0){
a = costHours * rates[student];
JOptionPane.showMessageDialog(null, dollar.format(costHours) + " hours at $" + rates[student] + " per hour yields a tuition of $" + dollar.format(a));
}else{
JOptionPane.showMessageDialog(null, "Credit hours cannot be zero.", "Invalid Input", JOptionPane.ERROR_MESSAGE);
}
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment