Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Cool problem with store

    Hello everybody. I ve got problem to a programme which store informations for bank clients. My programme has two classes the first is accountRecord for the information and second CreateTextFile which stores the variables in file. I use a while loop as i want to store a lot of objects. When i put the information for the first client and press enter the compiler does not continue.

  2. #2
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    this is the code for the second class


    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package account;
    import java.io.FileNotFoundException;
    import java.lang.SecurityException;
    import java.util.Formatter;
    import java.util.FormatterClosedException;
    import java.util.NoSuchElementException;
    import java.util.Scanner;
    
    /**
     *
     * @author George
     */
    public class CreateTextFile {
    
        private Formatter output;
    
        public void openfile(){
    
            try{
    
                output=new Formatter("clients.txt");
            }
            catch(SecurityException SecurityException){
    
                System.err.println("YOU DO NOT HAVE THE ACCESS TO THIS FILE.");
                System.exit(1);
            }
            catch(FileNotFoundException filesNotFoundException){
    
                System.err.println("Error creating file.");
                System.exit(1);
            }
        }
        public void addRecords(){
    
            AccountRecord record=new AccountRecord();
            Scanner input=new Scanner(System.in);
    
            System.out.printf("%s\n%s\n%s\n%s\n",
                    "To terminate input, type the end-of-file indicator",
                    "when you are prompted to enter input",
                    "...",
                    "........................");
            System.out.printf("%s\n%s", "enter account number(>0),first,lastname, and balance","?");
    
            while(input.hasNext()){
    
                try{
    
                    record.setAccount(input.nextInt());
                    record.setfirstName(input.next());
                    record.setlastName(input.next());
                    record.setBalance(input.nextDouble());
    
                    if(record.getAccount()>0){
    
                        output.format("%d %s %s %.2f\n", record.getAccount(),
                                record.getfirstName(),record.getlastName(),record.getBalance());
                    }
    
                    else{
    
                        System.out.println("Account must be greater than 0:");
                    }
                }
                catch(FormatterClosedException formatterClosedException){
    
                    System.err.println("Error writing to file.");
                    return;
                }
                catch(NoSuchElementException elementException){
    
                    System.err.println("Invalid input. Please try again.");
                    input.nextLine();
    
                    System.out.printf("%s\n%s", "enter account number(>0),first,lastname, and balance","?");
                }
            }
        }
        public void closeFile(){
    
            if(output !=null)
                output.close();
        }
        public static void main(String [] args){
    
            CreateTextFile application=new CreateTextFile();
    
            application.openfile();
            application.addRecords();
            application.closeFile();
        }
    }

  3. #3
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    In CreateTextFile class I can only create a blank file. I can t store the information.

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  5. #5
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

    Default

    ok i don t understand what you mean with flush the output, i guess not.

  6. #6
    Join Date
    Jan 2009
    Posts
    56
    Rep Power
    0

Similar Threads

  1. How to store/retrieve PNG image in/from RMS
    By jason-nexFIT-mobileXware in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-10-2008, 04:01 AM
  2. Extract xml to store into db
    By palanikumark in forum Advanced Java
    Replies: 3
    Last Post: 06-06-2008, 03:09 PM
  3. Store retrieve and delete
    By on7june in forum New To Java
    Replies: 1
    Last Post: 03-08-2008, 05:57 PM
  4. store file
    By kazitula in forum Java Applets
    Replies: 0
    Last Post: 02-17-2008, 09:45 PM
  5. I would then store a string...
    By susan in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 04:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •