Question: I need to convert the Java Program from an ArrayList, back into an Array in Java. import java.io.*; import java.util.*; public class prog23 { public
I need to convert the Java Program from an ArrayList, back into an Array in Java.
import java.io.*; import java.util.*; public class prog23 { public static void main(String[] args) throws IOException { program23 app = new program23(); app.appMain(); } } class program23 { BufferedReader stdin; int custNum; float begBal, overDraft; String monthEnd; int transNum; char transType; String transDate, overPenalty; float transAmt;
//ArrayList objects to hold transaction data ArrayList
void reportHeader() { System.out.print("****************************************** "); System.out.println("Program 23 Solution"); System.out.println("****************************************** "); } void initReport() { stdin = new BufferedReader(new InputStreamReader(System.in)); totCredits = 0; totDebits = 0; creditTransCtr = 0; totOverAmt = 0; lowDebitAmt = 5001; transNum = -11; } void getAccountInfo() throws IOException { System.out.print("Please enter the account number: "); custNum = Integer.parseInt(stdin.readLine()); System.out.print("Please enter the beginning balance for the account: "); begBal = Float.parseFloat(stdin.readLine()); System.out.print("Please enter the month end date for this cycle: "); monthEnd = stdin.readLine(); System.out.print("Please enter the overdraft penalty amount: "); overDraft = Float.parseFloat(stdin.readLine()); } void initRunningBal() { runBal = begBal; } void procTrans() throws IOException { getTransNum(); if (transNum != 0) { getTransDetails(); calculateTotalsAndRunBal(); //Update running balance to array list runningBal.add(runBal); calculateOverdraftAndPenalty(); //Update overPenalty to array list OverDraft.add(overPenalty); } }
void getTransNum() throws IOException { System.out.print(" Please enter the Transaction Number: "); transNum = Integer.parseInt(stdin.readLine());
//Update transactionNo array list transactionNo.add(transNum); }
void getTransDetails() throws IOException { System.out.print("Please enter the Trans Type: "); transType = (stdin.readLine().charAt(0));
//Update transactionType array list transactionType.add(transType); System.out.print("Please enter the Trans Amount: "); transAmt = Float.parseFloat(stdin.readLine());
//Update transactionAmt array list transactionAmt.add(transAmt); }
void calculateTotalsAndRunBal() { if (transType == 'C') { runBal = runBal + transAmt; totCredits = totCredits + transAmt; creditTransCtr = creditTransCtr + 1; } if (transType == 'c') { runBal = runBal + transAmt; totCredits = totCredits + transAmt; creditTransCtr = creditTransCtr + 1; } if (transType == 'D') { runBal = runBal - transAmt; totDebits = totDebits + transAmt; updateLows(); } if (transType == 'd') { runBal = runBal - transAmt; totDebits = totDebits + transAmt; updateLows(); } }
void calculateOverdraftAndPenalty() { if(runBal < 0) { runBal = runBal - overDraft; totOverAmt = totOverAmt + overDraft; overPenalty = "$" + Float.toString(overDraft); } else { overPenalty = ""; } } void updateLows() { if(transAmt < lowDebitAmt) { lowDebitAmt = transAmt; lowDebitNum = transNum; } }
//Displaying formatted transaction data void displayTransDetails() { //Formatting header System.out.format(" %-15s %-15s %-20s %-20s %-20s ", "Trans #", "Trans Type", "Trans Amt", "Running Bal", "OD Penalty Amt" ); //Printing all transactions for(int i=0; i
void calculateAverage() { avgCredit = totCredits / creditTransCtr; } void displaySummary() { System.out.println(" "); System.out.println("******************************************"); System.out.println("****MASCO Monthly Transaction Report Summary****"); System.out.println("Customer Account Number: \t\t" + custNum); System.out.println("Customer Beginning of Month Balance: \t" + begBal); System.out.println("Monthly Transaction Report Ending on: \t" + monthEnd); System.out.println("Overdraft Penalty Amount: \t\t" + overDraft); System.out.println("******************************************"); System.out.println("***************************************"); System.out.println("Customer End Balance:\t" + runBal); System.out.println("Total Credits $ Amount:\t" + totCredits); System.out.println("Total Debits $ Amount: \t" + totDebits); System.out.println("Total Overdraft Amount:\t" + totOverAmt); System.out.println("Average Credit Amount: \t" + avgCredit); System.out.println(); System.out.println("Low Debit $ Amount: \t" + lowDebitAmt); System.out.println("Low Debit Trans #:\t" + lowDebitNum); System.out.println("*******************************"); System.out.println("*******************************"); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
