Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to make this program work? I want the output looks like this Sample Output: Transaction Type: Deposit Account Number: 9876 Amount to Deposit: $123.45

How to make this program work? I want the output looks like this

Sample Output: Transaction Type: Deposit Account Number: 9876 Amount to Deposit: $123.45 Old Balance: $300.50 New Balance: $423.95

input can be whatever.

import java.util.*; import java.io.*; // need to input files public class BankAccount { public static void main(String[] args) throws IOException { Scanner keyboard=new Scanner(System.in); PrintWriter pw = new PrintWriter("bankoutput.txt"); final int MAXSIZE = 50;

int []acctnum = new int[MAXSIZE]; int num_accts = 0, test = 0; char select; double []balance = new double[MAXSIZE]; num_accts=readAccts(acctnum,balance, MAXSIZE, pw);

do { printAccts( acctnum, balance, num_accts, pw); menu(); System.out.println("Make a selection"); select=keyboard.next().charAt(0); switch(select) { case 'W': case 'w': withdrawal( acctnum, balance, num_accts, keyboard, pw); break; case 'D': case 'd':deposit(acctnum, balance, num_accts, pw); break; case 'N': case 'n': newAcct(acctnum, balance,num_accts, keyboard, pw ); break; case 'B': case 'b':balance( acctnum, balance, num_accts, pw); break; case 'q': case 'Q': System.out.println("further transcation has been terminated"); break; case 'x' : case 'X' : deleteAcct( acctnum, balance, num_accts, pw); break; default: pw.println("wrong"); } }while(select !='Q' && select !='q'); }

public static int readAccts(int[] acctnum, double[] balance, int max_accts, PrintWriter pw) throws IOException{ int numaccounts=0;

File outputFile = new File("input.txt"); Scanner output = new Scanner(outputFile);

while(output.hasNext()) { acctnum[numaccounts]=output.nextInt(); balance[numaccounts]=output.nextDouble(); numaccounts++; }

output.close(); return numaccounts; }

public static void menu() { System.out.println("W - withdrawal"); System.out.println("D - deposit "); System.out.println("N - new accounts"); System.out.println("B - balance"); System.out.println("Q - quit"); System.out.println("x- delete"); }

public static int findAcct(int[] acctnum, int num_accts, int account) { for(int i=0; i

public static void withdrawal(int[] acctnum, double[] balance, int num_accts, Scanner keyboard, PrintWriter pw) { int acct, pos; double withdraw;

System.out.println("Enter your account number: "); acct=keyboard.nextInt(); pos = findAcct(acctnum, num_accts, acct); if(pos== -1) pw.println("account not found"); else { System.out.println("Enter withdraw ammount: "); Scanner keyboard1=new Scanner(System.in); withdraw=keyboard1.nextDouble(); if(withdraw> balance[pos]) pw.println("Not enough funds"); else { balance[pos] -= withdraw; pw.println("Your withdrawl successful"); pw.println("succeed ");

} } }

public static void deposit(int[] acctnum, double[] balance, int num_accts, PrintWriter pw) {

int acct, pos; Scanner keyboard=new Scanner(System.in); // prompt user to enter account number System.out.println("Enter your account number: "); acct=keyboard.nextInt(); pos = findAcct(acctnum, num_accts, acct); if(pos== -1) pw.println("account not found"); else { // prompt user to enter amount to deposit System.out.println("Enter deposit ammount: "); double deposit1 = keyboard.nextDouble(); if(deposit1 < 0) // prompt user to enter postive amount pw.println("deposit amount must be a positive number" + ". Try again"); else { balance[pos] +=deposit1; pw.println("Your deposit successful"); pw.println("succeed "); } } }

public static int newAcct(int[] acctnum, double[] balance, int num_accts, Scanner input, PrintWriter pw ) throws IOException{ int pos , acct; double bal;

System.out.println("Welcome to our bank! Enter your new account"); acct=input.nextInt();

pos=findAcct(acctnum, num_accts, acct);

if(pos>=0) pw.println("Sorry, account number " + acct + " is taken"); else { acctnum[num_accts]=acct; balance[num_accts]=0; num_accts++; pw.println("account creaed!"); } return num_accts; }

public static void balance(int[] acctnum, double[] balance, int num_accts, PrintWriter pw) { int account, pos; double deposit; Scanner keyboard=new Scanner(System.in); //step one: prompt the user to enter their account number

System.out.print("Enter account number : ");

account = keyboard.nextInt();

//step 2: send the acctnum array, num_accts, AND account //to the findAcct method. Assign the method call to the variable pos.

pos = findAcct(acctnum, num_accts, account);

if (pos== -1) pw.println( "the account the user entered was not found"); else pw.println("Current balance $" + balance[pos]); }

public static void printAccts(int[] acctnum, double[] balance, int num_accts, PrintWriter pw) { for(int i=0; i

// enter an account you want to delete System.out.println("enter an account number you want to delete"); acct=keyboard.nextInt();

pos=findAcct(acctnum, num_accts, acct); if (pos==-1) pw.println("Accout number " +acct + " was not found"); else { num_accts --; for(int i = pos; i <= num_accts; i++) { acctnum[i] = acctnum [i + 1]; balance[i] = balance [i + 1]; } pw.println(acct + "accont was deleted ");

} return num_accts; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions

Question

What is meant by the term overpurchasing?

Answered: 1 week ago

Question

1. Organize and support your main points

Answered: 1 week ago

Question

3. Move smoothly from point to point

Answered: 1 week ago

Question

5. Develop a strong introduction, a crucial part of all speeches

Answered: 1 week ago