Answered step by step
Verified Expert Solution
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 ArrayListtransactions; /** 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
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