Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me in creating a few java classes! A. The Winter Park Bank maintains

ID: 666320 • Letter: P

Question

Please help me in creating a few java classes!

A. The Winter Park Bank maintains customer records in a random access file. Write an application that creates 9,000 blank records and then allows the user to enter customer account information, including an account number that is 9000 or less, a last name, and a balance. Insert each new record into a data file at a location that is equal to the account number. Assume that the user will not enter invalid account numbers. Force each name to eight characters, padding it with spaces or truncating it if necessary. Also assume that the user will not enter a bank balance greater than 99,000.00. Save the file as WinterParkBankFile.java.

B. Create an application that uses the file created by the user in Exercise A and displays all existing accounts in account-number order. Save the file as ReadWinterParkAccountsSequentially.java.

C. Create an application that uses the file created by the user in Exercise A and allows the user to enter an account number to view the account balance. Allow the user to view additional account balances until entering an application-terminating value. Save the file as ReadWinterParkAccountsRandomly.java.

Explanation / Answer

Note: Answered for A question only

WinterParkBankFile.java

import java.io.*;

import java.text.DecimalFormat;

import java.util.*;

class WinterParkFile//Class name declaration

{

     public static void main(String[] args) throws Exception//Main method

     {

          final int NUMBER_OF_RECORDS = 10000;

          final String ACCOUNT_NUMBER_FORMAT = "0000";

          final String NAME_FORMAT = "        ";

          final int NAME_LENGTH = NAME_FORMAT.length();//length

          System.out.println(NAME_LENGTH);

          final String BALANCE_FORMAT = "00000.00";

final String delimiter = ",";//Break string into tokens

String defaultRecord = ACCOUNT_NUMBER_FORMAT + delimiter + NAME_FORMAT + delimiter + BALANCE_FORMAT + System.getProperty("line.separator");

          final int RECORD_SIZE = defaultRecord.length();

          String accountString;

          int account;//Integer declaration

          String name;//String declaration

          double balance;//Double value

          final String STOP = "STOP";

          Scanner input = new Scanner(System.in);//Read values

          File f=new File("WinterBank");

RandomAccessFile file = new RandomAccessFile (f, "rw");

          createEmptyFile(f, defaultRecord, NUMBER_OF_RECORDS);

          try

          {

         

System.out.print("Enter account number or " + STOP + " => ");

accountString = input.nextLine();              while(!(accountString.equalsIgnoreCase(STOP)))//Loop starts

              {

                   account = Integer.parseInt(accountString);

System.out.print("Enter account holder name: #" + accountString + " => ");

                   name = input.nextLine();

                   StringBuilder sb = new StringBuilder(name);

                   sb.setLength(NAME_LENGTH);

                   name = sb.toString();

System.out.print("Enter Balance: #" + accountString + " => ");

                   balance = input.nextDouble();

                   input.nextLine();

DecimalFormat df = new DecimalFormat(BALANCE_FORMAT);

String s = accountString + delimiter + name + delimiter + df.format(balance) + System.getProperty("line.separator");

                   file.writeBytes(s);

System.out.println("Enter account number or " + STOP + " => ");

               accountString = input.nextLine();          

              }         

          }     

          catch(Exception e)

          {

              System.out.println("Error message: " + e);

          }

          file.close();

          input.close();

     }

public static void createEmptyFile(File file, String s, int lines)

     {

          try

          {

OutputStream outputStr = new BufferedOutputStream( new FileOutputStream(file));

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStr));

              for(int count = 0; count < lines; ++count)

              writer.write(s, 0, s.length());

              writer.close();

          }

          catch(Exception e)

          {

   System.out.println("Error message: " + e);//To print

          }

     }

}