Tuition.java tutorial program help
807589Sep 27 2008 — edited Sep 27 2008
I am working on a tutorial program Tuition.java from the Shelly Cashman series Java Programming book. I completed the below code according to instructions, but keep getting these compile errors.
Can anyone tell me where I'm going wrong?
Compile errors:
C:\Documents and Settings\Jay\My Documents\Jays School Papers\CISB 331 Java\Project 3\Tuition.java:94: cannot find symbol
symbol : variable tuition
location: class Tuition
total = tuition + fees;
^
C:\Documents and Settings\Jay\My Documents\Jays School Papers\CISB 331 Java\Project 3\Tuition.java:94: cannot find symbol
symbol : variable fees
location: class Tuition
total = tuition + fees;
^
C:\Documents and Settings\Jay\My Documents\Jays School Papers\CISB 331 Java\Project 3\Tuition.java:94: incompatible types
found : java.lang.String
required: double
total = tuition + fees;
^
3 errors
Tool completed with exit code 1
import java.io.*;
import java.text.DecimalFormat;
public class Tuition
{
public static void main(String[] args)
{
//Declare variables
int hours;
double fees, rate, tuition;
displayWelcome();
hours = getHours();
rate = getRate(hours);
tuition = calcTuition(hours, rate);
fees = calcFees(tuition);
displayTotal(tuition + fees);
}
// start the welcome() method
public static void displayWelcome()
{
System.out.println("Welcome to the Tuition Calculator program");
System.out.println();
}
//getHours() will receive the input from the user and use a Try and Catch statement for validation.
public static int getHours()
{
String strHours;
int hours = 0;
boolean done = false;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
while(!done) //Keep asking for integer input while input is in incorrect format.
{
//get hours from user.
System.out.println("Please enter your total credit hours: ");
strHours = dataIn.readLine();
//Validate input using Try
try
{
hours = Integer.parseInt(strHours);
done = true;
}
catch (NumberFormatException e) //Catch error and display response
{
System.out.println("Your entry was not in the correct format.");
}
}
}
public static double getRate(int hours) //Set hours rate based on amount of hours.
{
//declare variables
double rate;
if(hours > 15)
rate = hours * 44.50;
else
rate = hours * 50.00;
return rate;
}
public static double calcTuition(int hours, double rate) //Caclulate tuition and return it.
{
//declare variables
double tuition;
tuition = hours * rate;
return tuition;
}
public static double calcFees(double tuition) //Calculate total fees.
{
//declare variables
double fees;
fees = tuition * .08;
return fees;
}
public static void displayTotal(double total) //Calculate entire tuition costs and display.
{
//declare variables
//double total;
total = tuition + fees;
DecimalFormat twoDigits = new DecimalFormat("$#000.00");
System.out.println("Your Tuition is " + total);
}
}
Thanks!!