java - How to prime multiple blank records and then add data to them -


i've been struggling trying understand area in java, figured perhaps online it. basically, need "prime" 9,000 blank records (for bank) , choose enter data in specific areas (i.e. account number, name, balance).

i know have use loops don't know should go. currently, can create 9,000 records, after entering data 1 record duplicates 9,0000 times, instead of putting record in 1 specific spot , leaving rest blank.

import java.nio.file.*; import java.io.*; import static java.nio.file.standardopenoption.*; import java.util.scanner;  public class writeemployeefile {   public static void main(string[] args)   {     scanner input = new scanner(system.in);     file myfile = new file ("c:\\users\\ussi\\desktop\\customerrecords.txt");     path file = paths.get("c:\\users\\ussi\\desktop\\customerrecords.txt");     string s = "000, ,00.00" +     system.getproperty("line.separator");     string delimiter = ",";     int account;     string name;     double balance;     final int quit = 999;     final int max = 9001;      try     {         outputstream output = new         bufferedoutputstream(files.newoutputstream(file, create));         bufferedwriter writer = new         bufferedwriter(new outputstreamwriter(output));         system.out.print("enter client account number: ");         account = input.nextint();          while(account != quit)         {             system.out.print("enter last name client #" +             account + ": ");             input.nextline();             name = input.nextline();             system.out.print("enter account balance: ");             balance = input.nextdouble();             s = account + delimiter + name + delimiter + balance;              for(int count = 0; count < max; ++count)                 writer.write(s, 0, s.length());              writer.newline();             system.out.print("enter next id number or " +             quit + " quit: ");             account = input.nextint();         }         writer.close();     }     catch(exception e)     {         system.out.println("message: " + e);     }  } } 

edit: these assignment instructions (if curious or if didn't explain clearly.

the winter park bank maintains customer records in random access file. write application creates 9,000 blank records , allows user enter customer account information, including account number 9999 or less, last name, , balance. insert each new record data file @ location equal account number. assume user not enter invalid account numbers. force each name 8 characters, padding spaces or truncating if necessary. assume user not enter bank balance greater 99,000.00. save file winterparkbankfile.java.

not sure want, give idea of instantinating 9000 bank accounts , access them place in list put:

class bankaccount {     int number;     int balance;     string name;      public static void main(string[] args) {          list<bankaccount> accounts = new arraylist<bankaccount>();          (int = 0; < 9000; i++) {             accounts.add(new bankaccount());         }          // fill these variables console want         int = 0;         int balancereadfromconsole = 0;         int numberreadfromconsole = 0;          accounts.get(i).name = "whatever want set i-th account's name";         accounts.get(i).balance = balancereadfromconsole;         accounts.get(i).number = numberreadfromconsole;      } } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -