PDA

View Full Version : Newbie Help (Tax Script)


mattd8752
06-18-2007, 02:05 AM
I've got a tax script here, and I'd like to have some help debugging it.
Unless the error is a typo, please don't tell me the problem. Please tell me what I need to do to make it work. (don't give me a fixed script).

The script is:
import java.io.*;
class rates {
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );

rates() {
System.out.println("Menu:");
System.out.println("(1) Set Tax Rate");
System.out.println("(2) Calculate Item Price");
System.out.println("------------------------");
System.out.println("Please enter the number beside your menu option.");
}
void setrate() throws IOException {
System.out.println("Enter the tax percentage.");
String input = stdin.readLine();
double rate = double.doubleValue(input);
FileOutputStream fout;
try {
fout = new FileOutputStream ("tax.txt");
new PrintStream(fout).println (rate);
fout.close();
}
catch (IOException e) {
System.err.println ("Unable to write to file");
System.exit(-1);
}
}
void getrate() throws IOException {
FileInputStream fin;
try {
fin = new FileInputStream ("tax.txt");
System.out.println(new DataInputStream(fin).readLine());
fin.close();
}
catch (IOException e) {
System.err.println ("Unable to read from file");
System.exit(-1);
}
}
void getprice() throws IOException {
double rates tax = new rates();
double tax = tax.getrate();
double tax = tax*0.01;
System.out.println("Enter a price.");
String input = stdin.readLine();
double price = double.doubleValue(input);
double onlytax = tax * price;
double withtax = onlytax + price;
System.out.println("Price: | " + price);
System.out.println("Tax: | " + onlytax);
System.out.println("-------------------");
System.out.println("Total: | " + withtax);
}
}


Anyway, here are the errors (during compiling):

rates.java:16: class expected
double rate = double.doubleValue(input);
^
rates.java:16: ';' expected
double rate = double.doubleValue(input);
^
rates.java:16: not a statement
double rate = double.doubleValue(input);
^
rates.java:16: ';' expected
double rate = double.doubleValue(input);
^
rates.java:41: ';' expected
double rates tax = new rates();
^
rates.java:46: class expected
double price = double.doubleValue(input);
^
rates.java:46: ';' expected
double price = double.doubleValue(input);
^
rates.java:46: not a statement
double price = double.doubleValue(input);
^
rates.java:46: ';' expected
double price = double.doubleValue(input);
^
9 errors

javabits
06-18-2007, 06:54 PM
There is a difference between double and Double.

double is the primitive type. Double is an object that represents a double.

The Double object has the method doubleValue which returns a double. See if you can solve your error with this information and if you still have problems let everyone know.

semper fi...