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

JAVA Create a menu-driven program using application to manage a bank account. It

ID: 3674339 • Letter: J

Question

JAVA

Create a menu-driven program using application to manage a bank account. It supports following operations:

Deposit money;

Withdraw money;

Check balance;

Add new account;

Delete account.

Application is driven by a text menu. Application stores the data in a .txt file. You must initial your .txt file with at least three accounts.

Data requirements:
It should have following attributes:

Account_no

Account_name

Balance

Note- use appropriate datatypes.

Required functionality: (User should be able to validate)

1. It should validate account_no to deposit money.
2. It should validate that, user cannot deposit negative amount.

3. It should validate account_no to withdraw money.

It should validate if amount to be withdrawn is less than the available funds in the account.

It should be able to add new account.

It should be able to delete existing account.

Finally, the menu should ask user to press key # to quit.

Remarks in program:

You must include remarks for every operations and attributes in your code

Explanation / Answer

/*this program can only take upto 500 records */
import java.io.*;
class bank_with_file_chegg
{
int len;
int index;
long acc[]=new long[500];
String name[]=new String[500];
double balance[]= new double[500];
bank_with_file_chegg()
{
index=0;
len=0;
}
public void menu()throws IOException
{
int flag=0;
while(flag!=1)
{
   //Providing the user with the menu

System.out.println("Enter Your Choice ");
System.out.println("Press a: To Deposit an Ammount");
System.out.println("Press b: To Withdraw an Amount");
System.out.println("Press c: To Create a New Account");
System.out.println("Press d: To Delete an Account");
System.out.println("Press #: To Quit");
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
char ch=(ob.readLine()).charAt(0);

//Using the switch statement to process the request by the user.(a,,b,c..)
switch(ch)
{
case 'a': System.out.println("Enter the Amount");
double amt= Double.parseDouble(ob.readLine());
System.out.println("Enter the Account Number");
long accn=Long.parseLong(ob.readLine());
deposit(amt,accn);
break;
case 'b': System.out.println("Enter the Amount");
amt= Double.parseDouble(ob.readLine());
System.out.println("Enter the Account Number");
accn=Long.parseLong(ob.readLine());
withdraw(amt,accn);
break;
case 'c': System.out.println("Please Punch in the New Details");
createAccount();
break;
case 'd': System.out.println("Enter the Account Number to be Deleted");
accn=Long.parseLong(ob.readLine());
deleteAccount(accn);
break;
case '#': flag=1;break;
default : System.out.println("Please Enter a Valid Input");
}
}
}
// checking whether the account number is valid or not
boolean checkAccn(long accn)
{
for (int i=0;i<acc.length;i++)
{
if(accn==acc[i])
{
index=i;
return true;
}
}
return false;
}
// depositing the amount of money required by the user.
void deposit(double amt,long accn)
{
if(checkAccn(accn) && (amt>=0))
{
balance[index]+=amt;
}
else
{
System.out.println("Account Number is Invalid or Amount is a negative quantity");
}
}
// Function to deal with the withrawal request.
void withdraw(double amt,long accn)
{
if(checkAccn(accn)) // checking whether the amount entered is less than the current balance
{
if(balance[index]>=amt)
{
System.out.println("Amount Withdrawn: "+amt);
balance[index]= balance[index]-amt;
System.out.println("Amount Available: "+balance[index]);
}
else
{
System.out.println("Insufficient Funds");
System.out.println("Availale Balance: "+balance[index]);
}
}
else
{
System.out.println("Account Number is Invalid");
}
}
// Function to create the account.
void createAccount()throws IOException
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); //buffer reader being initialised to take user input
System.out.println("Amount Name:");
String na=ob.readLine();
int length=len;
name[length]=na;
System.out.println("New Account Number:");
long accn=Long.parseLong(ob.readLine());
acc[length]=accn;
System.out.println("Initial Amount:");
double amt=Double.parseDouble(ob.readLine());
balance[length]=amt;
System.out.println("Account Successfully Created");
}
// Deleting account on users request.
void deleteAccount(long accn)
{
if(checkAccn(accn))
{
name[index]=null;
}
else
{
System.out.println("Enter A Valid Account Number");
}
}
// Reading the current data present in the file.
void readFile()throws IOException
{
BufferedReader br=null;
br = new BufferedReader(new FileReader("test.txt"));
int i=0;
String sCurrentLine;
           while ((sCurrentLine = br.readLine()) != null) {
               acc[i]=Long.parseLong(sCurrentLine);
               sCurrentLine = br.readLine();
               name[i]=sCurrentLine;
               sCurrentLine = br.readLine();
               balance[i]=Double.parseDouble(sCurrentLine);
               ++i;
           }
           len=i;
}
//The current data is being written to the file
void writeFile()throws IOException
{
PrintWriter writer = new PrintWriter("test.txt", "UTF-8"); //print writer used to write contents to the file again.
int i=0;
while(i<=len)
{
if(name[i]!=null)
{
writer.println(acc[i]);
writer.println(name[i]);
writer.println(balance[i]);
++i;
}
}
writer.close();
}
public static void main(String args[])throws IOException
{
bank_with_file_chegg ob= new bank_with_file_chegg();
ob.readFile();
ob.menu();
ob.writeFile();
}
}