Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello i just want you remove the file.io things from this code by the way it's java programing language package atmoperation; import java.io.FileNotFoundException; import java.io.IOException;
Hello i just want you remove the file.io things from this code by the way it's java programing language
package atmoperation; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.NoSuchFileException; import java.nio.file.Paths; import java.util.Scanner; class Account { long[] accountNo = new long[10]; String[] fname = new String[10]; String[] lname = new String[10]; double[] balance = new double[10]; int n = 0; Account() { this.accountNo[n] = 0; this.lname[n] = ""; this.fname[n] = ""; this.balance[n] = 0; } void setAccount(long accountNo, String fname, String lname, double balance) { this.accountNo[n] = accountNo; this.lname[n] = lname; this.fname[n] = fname; this.balance[n] = balance; n++; } double getBalance(long accountNo) { for (int i = 0; i < n; i++) if (this.accountNo[i] == accountNo) return balance[i]; return -1; } void deposit(long accountNo, double amt) { for (int i = 0; i < n; i++) if (this.accountNo[i] == accountNo) { balance[i] += amt; System.out.println("Transaction successful"); } } void withdraw(long accountNo, double amt) { for (int i = 0; i < n; i++) if (this.accountNo[i] == accountNo) { if (balance[i] > amt) { balance[i] -= amt; System.out.println("Transaction successful"); } else System.out.println("Insuficcient balance"); } } void report() { for (int i = 0; i < n; i++) System.out.println("Account details: AccountNumber: " + this.accountNo[i] + " Name: " + this.fname[i] + " Pin: " + this.lname[i] + " Balance: " + this.balance[i]); } void delete(long accountNo) { for (int i = 0; i < n; i++) if (this.accountNo[i] == accountNo) { for (int j = i; j < n - 1; j++) { this.accountNo[j] = this.accountNo[j + 1]; this.lname[j] = this.lname[j + 1]; this.fname[j] = this.fname[j + 1]; this.balance[j] = this.balance[j + 1]; } } n--; } int check(long acc) { for (int i = 0; i < n; i++) if (this.accountNo[i] == acc) return 1; return 0; } } public class ATMOperation { public static void main(String[] args) throws IOException { int c, pin, k = 0; long acc; double amt; int flag = 0; Account ac = new Account(); Scanner sc = new Scanner(System.in); do { System.out.println(" Enter the file name"); String file = sc.nextLine(); try { Scanner fr = new Scanner(Paths.get(file)); file = "C:\\Users\\Apple\\Desktop/accounts.txt"; while (fr.hasNext()) { flag = 1; String fname = fr.next(); String lname = fr.next(); acc = fr.nextLong(); double bal = fr.nextDouble(); ac.setAccount(acc, fname, lname, bal); } } catch (NoSuchFileException exception) { System.out.println("The file was not found."); } } while (flag == 0); do { System.out.println(" Menu"); System.out.println(" Select one of the following operations: " + " 1. check balance" + " 2. withdraw" + " 3. deposit" + " 4. Exit " + " choice: "); c = sc.nextInt(); switch (c) { case 1: do { System.out.println("Enter account no: "); acc = sc.nextLong(); k = ac.check(acc); } while (k == 0); System.out.println("Balance: " + ac.getBalance(acc)); break; case 2: do { System.out.println("Enter account no: "); acc = sc.nextLong(); k = ac.check(acc); } while (k == 0); System.out.println("Enter amount: "); amt = sc.nextDouble(); ac.withdraw(acc, amt); break; case 3: System.out.println("Enter account no: "); acc = sc.nextLong(); System.out.println("Enter amount: "); amt = sc.nextDouble(); ac.deposit(acc, amt); break; default: break; } } while (c < 4); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started