Create a Bank Account class that contains four instance variables: an account nu
ID: 3728079 • Letter: C
Question
Create a Bank Account class that contains four instance variables: an account number (int), a last name (String), a first name (String) and the balance (double). It should also have methods you think appropriate as well as the requisite accessor and mutator methods and necessary constructors. Design a tester program that uses a Random Access File (RAF) to store (writes to and reads out) the current information for each Bank Account object. When working with Random Access Files, you must give each value a fixed size that is sufficiently large. As a result, every record (object) will have the same size. Integers obviously are 4 bytes; doubles 8 bytes and Strings are of a fixed byte size of your choosing. The tester should ask the user to enter an account number and an amount to deposit. If the account does not currently exist in the RAF, it should generate an account number and get th user's first and last name. Each account number must be unique. It should then write out that account number's data to the RAF. be added to the current balance. After adding the deposit, the user should be informed of the account's new balance. The user can have multiple accounts or could be a bank teller entering deposits from the Business Drop Box. Hence, a user should be asked if they want to make another deposit(s) If the account already exists, the deposit will When there are at least 10 accounts in the RAF, use a loop to read out the current information for all account numbers. PrintScreen your results with all the data for four instance variables of the BankAccount object for all accounts. the At this point, the program should also allow the user to append more new accounts to the file and add additional deposits to at least three of the existing accounts. Use some of the Random Access File methods to locate an object and print it out, determine the size of the file as well as interrogate the file to verify or check a customer's name or a balance and edit the account record if necessary. PrintScreen again after you have added more accounts, added new deposits to existing accounts and used some of the RAF methods a suggested aboveExplanation / Answer
Source Code:-
===================
package com.venkanna;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Scanner;
class Bank_Account
{
int Account_id;
String FirstName;
String LastName;
double deposit_Balance;
Bank_Account(int Account_id,String FirstName,String LastName,Double deposit_Balance)
{
this.Account_id=Account_id;
this.FirstName=FirstName;
this.LastName=LastName;
this.deposit_Balance=deposit_Balance;
}
public void add(FileWriter fw,int Account_id,String FirstName,String LastName,double deposit_Balance) throws IOException
{
fw.write(" ");
try
{
fw.write("#");
fw.write(Account_id+"|"+FirstName+"|"+LastName+"|"+deposit_Balance);
fw.write("#");
fw.write(" ");
}
catch(Exception e)
{
System.out.println(e);
}
fw.close();
}
}
public class Tester
{
public static void main(String[] args) throws IOException
{
Scanner sc=new Scanner(System.in);
Bank_Account accouninfo = null;
String firstname,lastname;
double balance;
int accountno,size,option,flag=1,index=0;
LinkedList<Bank_Account> record = new LinkedList<Bank_Account>();
String recordData[];
String basePath = new File("F:\Workspace_Luna\Challenging_Tasks\").getAbsolutePath();
String recordPath = basePath.concat("/AccountList.txt");
FileWriter fw=new FileWriter("F:\Workspace_Luna\Challenging_Tasks\AccountList.txt");
System.out.println(" Please Enter How Many Records you want to enter");
size=sc.nextInt();
for(int i=0;i<size;i++)
{
System.out.println("Please Enter Account Number");
accountno=sc.nextInt();
System.out.println("Please Enter Accountant FirstName");
firstname=sc.next();
System.out.println("Please Enter Accountant LastName");
lastname=sc.next();
System.out.println("Please Enter Deposit Balance:");
balance=sc.nextDouble();
accouninfo=new Bank_Account(accountno,firstname,lastname,balance);
record.add(accouninfo);
try
{
fw.write("#");
fw.write(accountno+"|"+firstname+"|"+lastname+"|"+balance);
fw.write("#");
fw.write(" ");
}
catch(Exception e)
{
System.out.println(e);
}
}
fw.close();
try
{
System.out.println("**** All Records in BankAccount List ****");
File file2 = new File("F:\Workspace_Luna\Challenging_Tasks\AccountList.txt");
BufferedReader file = new BufferedReader(new FileReader(file2));
String line;
String input = "";
while ((line = file.readLine()) != null)
{
System.out.println(line);
input += line + ' ';
line = line.replaceFirst("#", "");
recordData= line.split("[|]");
}
file.close();
while(true)
{
System.out.println("**** Welcome to the Index Based Record****");
System.out.println("**** MENU *******");
System.out.println("1.To Add Bank Account");
System.out.println("2.Search Account Record");
System.out.println("3.Delete Account Record");
System.out.println("4.Quit");
System.out.println("Please Choose any Option");
option=sc.nextInt();
switch(option)
{
case 1:
System.out.println("Please Enter Account Number");
accountno=sc.nextInt();
System.out.println("Please Enter Accountant FirstName");
firstname=sc.next();
System.out.println("Please Enter Accountant LastName");
lastname=sc.next();
System.out.println("Please Enter Deposit Balance:");
balance=sc.nextDouble();
accouninfo=new Bank_Account(accountno,firstname,lastname,balance);
record.add(accouninfo);
accouninfo.add(fw,accountno,firstname,lastname,balance);
break;
case 2:
System.out.println("Please Account Number to DepositBalance");
accountno=sc.nextInt();
for(Bank_Account records:record)
{
if(records.Account_id==accountno)
{
System.out.println("Please Enter The Deposit Amount");
balance=sc.nextDouble();
records.deposit_Balance+=balance;
System.out.println("Amount Deposited Successfully");
flag=0;
break;
}
}
if(flag==1)
System.out.println("The Account Number Not Found");
System.out.println("New Records in Bank");
for(Bank_Account records:record)
{
System.out.println(records.Account_id+" "+records.FirstName+" "+records.LastName+" "+records.deposit_Balance);
}
break;
case 3:
System.out.println("Please Account Number to DeleteAccount");
accountno=sc.nextInt();
for(Bank_Account records:record)
{
if(records.Account_id==accountno)
{
record.remove(index);
System.out.println("Account Deleted Successfully");
flag=0;
break;
}
}
if(flag==1)
System.out.println("The Account Number Not Found");
System.out.println("New Records in Bank");
for(Bank_Account records:record)
{
System.out.println(records.Account_id+" "+records.FirstName+" "+records.LastName+" "+records.deposit_Balance);
}
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid Option");
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
sc.close();
}
}
Sample Output:-
================
Please Enter How Many Records you want to enter
3
Please Enter Account Number
123
Please Enter Accountant FirstName
venkanna
Please Enter Accountant LastName
koothada
Please Enter Deposit Balance:
50000
Please Enter Account Number
345
Please Enter Accountant FirstName
Ammulu
Please Enter Accountant LastName
koothada
Please Enter Deposit Balance:
23000
Please Enter Account Number
567
Please Enter Accountant FirstName
Sindhoora
Please Enter Accountant LastName
koothada
Please Enter Deposit Balance:
89000
**** All Records in BankAccount List ****
#123|venkanna|koothada|50000.0#
#345|Ammulu|koothada|23000.0#
#567|Sindhoora|koothada|89000.0#
**** Welcome to the Index Based Record****
**** MENU *******
1.To Add Bank Account
2.Search Account Record
3.Delete Account Record
4.Quit
Please Choose any Option
2
Please Account Number to DepositBalance
345
Please Enter The Deposit Amount
27000
Amount Deposited Successfully
New Records in Bank
123 venkanna koothada 50000.0
345 Ammulu koothada 50000.0
567 Sindhoora koothada 89000.0
**** Welcome to the Index Based Record****
**** MENU *******
1.To Add Bank Account
2.Search Account Record
3.Delete Account Record
4.Quit
Please Choose any Option
4
outputfile:-
#123|venkanna|koothada|50000.0#
#345|Ammulu|koothada|23000.0#
#567|Sindhoora|koothada|89000.0#