Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
3 Errors in Java code. Please help.?
Hi I need some help with this code please: import java.io.*;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Tuition
{
public static void main(String[] args)
{
//Declare Variables
int hours;
double fees, rate, tuition;
//Call Methods
displayWelcome();
hours = getHours();
rate = getRate(hours);
tuition = calcTuition(hours, rate);
fees = calcFees(tuition);
displayTotal(tuition + fees);
}
public static void displayWelcome()
{
System.out.println("Welcome to the Tuition and Fees Calculator");
}
public static int getHours()
{
//Declare Variables
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String strHours;
int hours = 0;
try
{
//Prompt User for input
System.out.println("\t\tEnter total number of hours used by students");
hours = dataIn.readLine();
hours = Integer.parseInt(strHours);
}
catch(NumberFormatException e)
{
System.out.println("Please input whole numbers");
}
return hours;
}
public static double getRate(int hours)
{
if (hours > 15)
{
System.out.println("\t\tCalculate rate per credit hour");
}
else
if(hours < 15)
{
System.out.println("Credit hours are inaccurate");
}
return Rate;
}
public static double calcTuition(int hours, double rate)
{
//Accept two values
rate = rate * hours;
return Tuition;
}
public static double calcFees(double tuition)
{
//Accept double Value
double fees;
fees = tuition * 0.8;
return fees;
}
public static void displayTotal(double total)
{
//Construct DecimalFormat pattern for currency
DecimalFormat twoDigits = new DecimalFormat("$000.00");
double fees;
double tuition;
System.out.println("Your total is: "+ tuition+".");
}
}
The Errors are: java:49: error: incompatible types
hours = dataIn.readLine();
java:74: error: cannot find symbol
return Rate;
java:82: error: cannot find symbol
return Tuition;
In the dataIn.readLine statement, I have hours twice because I dont know what else to use. I have tried all the others like rate, tuition etc, but cant come right there. Also the two return statements; rate and tuition are incorrect. Could someone please assist me here.
Thank You. God Bless :-)
2 Answers
- James BondLv 79 years agoFavorite Answer
Correct like this
hours=Integer.parseInt(dataIn.readLine());
return rate;
return tuition;
- 9 years ago
You might want to keep the case of the variable names the same, that is to say rate =\= Rate
not sure about the first error, http://stackoverflow.com/questions/5845750/readlin... might help you there