I need to write my registry to a method to write my registry to a file and then read the file back. It creates the file just fun but doesn't write any of the information to the file. Can anyone tell me why it isn't writing the information to the file.
Thanks!
import java.util.Scanner;
import java.io.*;
public class account {
private static String name;
private static int checkNum;
protected static double balance;
private static double withdraw;
private static double deposit;
private double withdrawAmnt;
private double depositAmnt;
static double newAmnt;
static Scanner scan = new Scanner(System.in);
public account(){
name = null;
checkNum = 0;
balance = 0;
withdraw = 0;
deposit = 0;
}//End constructor
public static String getName(){
return name;
}//End getName
public static void setName(String newName){
name = newName;
}//End setName
public static int getCheckNum(){
return checkNum;
}//End getCheckNum
public static void setCheckNum(int newCheckNum){
checkNum = newCheckNum;
}//End setCheckNum
public static double getBalance(){
System.out.println("Your balance is:" + balance);
return balance;
}//End getBalance
public static void setBalance(double newBalance){
balance = newBalance;
//System.out.println("Your balance is :" + balance);
}//End setBalance
public double getWithdraw(){
return withdraw;
}//End getWithdraw
public void setWithdraw(double newWithdraw){
withdraw = newWithdraw;
}//End setWithdraw
public double getWithdrawAmount(){
return withdrawAmnt;
}//End getWithdrawAmount
public double getDepositAmount(){
return depositAmnt;
}//End getDepositAmount
public static double withdraw(){
System.out.println("Please enter the amount you wish to withdraw:");
withdraw = scan.nextDouble();
newAmnt = balance - withdraw;
if(newAmnt <= 0){
System.out.println("ERROR: Insufficent funds!");
System.exit(1);
}//End if
//System.out.println("Your new balance is:" + newAmnt);
return balance - withdraw;
}//End withdraw
public static double deposit(){
System.out.println("Please enter the amount to deposit:");
deposit = scan.nextInt();
newAmnt = balance + deposit;
System.out.println("Your new balance is:" + newAmnt);
return balance + deposit;
}//End deposit
public static void Registry(){
System.out.println("Enter your id number:");
account.setName(scan.next());
System.out.println("Enter your check number");
account.setCheckNum(scan.nextInt());
System.out.println("Enter the check amount :");
account.setBalance(scan.nextDouble());
}//End Registry
public static void printRegistry(){
System.out.println("Your id is:" + account.getName());
System.out.println("Your check number is: " + account.getCheckNum());
System.out.println("Your balance is: " + account.getBalance());
}//End printRegistry
public static void fileWriter() throws IOException{
try{
BufferedWriter out = new BufferedWriter(new FileWriter("Account"));
out.write(account.getName());
out.write(account.getCheckNum());
out.write((int) account.getBalance());
}catch(IOException e){
System.out.println("ERROR: Could not write to file!");
System.exit(1);
}
}//End fileWriter
public static void fileReader(){
try{
BufferedReader in = new BufferedReader(new FileReader ("Account"));
String str;
while((str = in.readLine()) != null){
System.out.println(str);
}
in.close();
}catch(IOException e){
System.out.println("ERROR: Could not read from file!");
System.exit(1);
}
}//End fileReader
public static void main(String[] args) throws IOException{
userInterface user = new userInterface();
user.Driver();
}//End Main
}//End Account

New Topic/Question
Reply




MultiQuote







|