K
klub
okay basically im a new java programmer and am trying to make a simple
bank account typish program... one that you can deposit and withdraw
and all and the balance will be read from/writen to a file, so that it
can be a permanent use. I use JCreator and compile/run directly in the
program. Here is my code:
import static java.lang.System.out;
import java.util.Scanner;
import java.io.*;
class bank {
public static void main (String args []) throws IOException {
Scanner inputScanner = new Scanner(System.in);
Scanner balanceScanner = new Scanner(new File("C:\\Documents and
Settings\\Caleb\\My Documents\\java\\balance.txt"));
double balance = balanceScanner.nextDouble();
out.println("Your account balance is $" + balance);
out.println("Would you like to make a deposit or withdrawal?");
out.println("d=deposit, w=withdrawal");
String action = inputScanner.next();
if (action.equals("d")) {
out.println("How much would you like to deposit?");
double depositAmount = inputScanner.nextDouble();
balance = balance + depositAmount;
out.println("Your balance is now $" + balance);
FileWriter out = new FileWriter("C:\\Documents and
Settings\\Caleb\\My Documents\\java\\balance.txt");
out.write(balance);
out.close();
} if (action.equals("w")) {
out.println("How much would you like to withdraw?");
double withdrawalAmount = inputScanner.nextDouble();
balance = balance - withdrawalAmount;
out.println("Your balance is now $" + balance);
}
}
}
The error message it shows is: "Cannot find symbol method
write(double), line 24, which is out.write(balance);... and i dont have
any clue how to fix it so that the double variable "balance" will be
written back to that file
bank account typish program... one that you can deposit and withdraw
and all and the balance will be read from/writen to a file, so that it
can be a permanent use. I use JCreator and compile/run directly in the
program. Here is my code:
import static java.lang.System.out;
import java.util.Scanner;
import java.io.*;
class bank {
public static void main (String args []) throws IOException {
Scanner inputScanner = new Scanner(System.in);
Scanner balanceScanner = new Scanner(new File("C:\\Documents and
Settings\\Caleb\\My Documents\\java\\balance.txt"));
double balance = balanceScanner.nextDouble();
out.println("Your account balance is $" + balance);
out.println("Would you like to make a deposit or withdrawal?");
out.println("d=deposit, w=withdrawal");
String action = inputScanner.next();
if (action.equals("d")) {
out.println("How much would you like to deposit?");
double depositAmount = inputScanner.nextDouble();
balance = balance + depositAmount;
out.println("Your balance is now $" + balance);
FileWriter out = new FileWriter("C:\\Documents and
Settings\\Caleb\\My Documents\\java\\balance.txt");
out.write(balance);
out.close();
} if (action.equals("w")) {
out.println("How much would you like to withdraw?");
double withdrawalAmount = inputScanner.nextDouble();
balance = balance - withdrawalAmount;
out.println("Your balance is now $" + balance);
}
}
}
The error message it shows is: "Cannot find symbol method
write(double), line 24, which is out.write(balance);... and i dont have
any clue how to fix it so that the double variable "balance" will be
written back to that file