/*
Program:
4.3
Programmer:
Brad Shedd
Date:
May 10, 2006
File:
Tuition.java
Purpose:
Calculates tuition and fees for their
students.
*/
import java.io.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public
class
Tuition
{
public
static
void
main(String[]arg)
{
//declare
variables
int
hours;
double
fees, rate, tuition;
//method
calls
displayWelcome();
hours =
getHours();
rate =
getRate(hours);
tuition =
calcTuition(hours, rate);
fees =
calcFees(tuition);
displayTotal(tuition + fees);
finish();
}
// end main
public
static
void
displayWelcome()
{
JOptionPane.showMessageDialog(null,
"Welcome to the Tuition Program","Welcome",JOptionPane.PLAIN_MESSAGE);
}
// end
displaywelcome
public
static
int
getHours()
{
// declare
method variables
int
hours = 0;
boolean
done =
false;
// loop
while not done
while
(!done)
{
String strHours = JOptionPane.showInputDialog(null,"Enter
the total amount of hours, or click Cancel to exit:");
if
(strHours ==
null) finish();
try
{
hours = Integer.parseInt(strHours);
if
(hours <= 0)
throw
new
NumberFormatException();
else
done =
true;
}
catch(NumberFormatException
e)
{
JOptionPane.showMessageDialog(null,"Your
entry was not in the proper format.","Error",JOptionPane.INFORMATION_MESSAGE);
}
}
return
hours;
}
// end
gethours
public
static
double
getRate(int hours)
{
double
rate;
if
(hours > 15) rate = 50.00;
else
rate = 44.50;
return
rate;
}
// end
getRate
public
static
double
calcTuition(int hours,
double
rate)
{
double
tuition;
tuition =
rate * hours;
return
tuition;
}
// end
calcTuition
public
static
double
calcFees(double tuition)
{
double
fees;
fees =
tuition * 0.08;
return
fees;
}
// end
calcFees
public
static
void
displayTotal(double total)
{
DecimalFormat twoDigits =
new
DecimalFormat("$###0.00");
System.out.println();
System.out.println("\tYour
total is: " + twoDigits.format (total) +".");
System.out.println();
}
// end
dispalyTotal
public
static
void
finish()
{
System.exit(0);
}
}
// end Tuition