Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Correct the bugs located in the bank account driver java file: Here you will find the txt file and two bank acc files (DO NOT

Correct the bugs located in the bank account driver java file:

Here you will find the txt file and two bank acc files (DO NOT need correction): https://pastebin.com/0ZTPkYyV

/** * Code to create a bank account and make transactions based on amounts read in from an input file * NOTE: there are bugs including those causing compilation errors and runtime logical problems * * @author */ import java.util.*; import java.io.File; import java.io.IOException; public class lab { static ArrayList transactions; /** stores the data retrived from the file */ static long startTime, endTime; /** variable used to compute the run-time */ static BankAcc account; // NOTE: use of interface for declaring a variable /** Reads numbers from the provided input filename and stores them in an ArrayList */ static private void readFile(String inpFileName) { try { File inputFile = new File(inpFileName); Scanner input = new Scanner(inputFile); transactions = new ArrayList(); Float element,max; int maxPos,count=0; // reads elements from a file and stores them in an ArrayList while (input.hasNextFloat()){ element = input.nextFloat(); count++; transactions.add(element); } input.close(); // print on the terminal each amount transacted System.out.printf("There are %d transactions in the input file: ",count); short cnt=1; for (Float value: transactions){ System.out.printf("Transaction %d) ",cnt++); if(value<0) account.withdraw(Math.abs(value)); else account.deposit(value); } // find the maximum absolute transaction amount // (uses a random index to start the search) Random generator = new Random(); int index = generator.nextInt(count); max = abs(transactions.get(index)); maxPos =index; for(int i=0;i value){ max = value; maxPos=(index+i)%count; } } //output results System.out.println(" The maximum transaction amount is "+max+", the "+maxPos+"th transaction. "); // new account created, amount deposited, transfer performed BankAccount account2 = new BankAccount("swissBankAcc"); account2.deposit(1000000.01f); account2.transfer(1000.0f,account); } catch (IOException e) { System.err.println("IOException: input file "+inpFileName+" not found!"); } } //end readFile() /** main method: reads from input file, performs transactions, computes run time */ public static void main(String args[]) { startTime = System.currentTimeMillis(); account= new BankAccount("piggyBank"); // new Bank Account created readFile("lab1a.txt"); endTime = System.currentTimeMillis(); System.out.println(" Total time taken: " + (endTime - startTime) + " milliseconds"); } //end main } 

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

5. What information would the team members need?

Answered: 1 week ago

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago