Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JAVA, Given CODE need to be optmized Optimization and Exception Handling Refine Source Code for singular bank account program. Look for code optimization conventions

In JAVA, Given CODE need to be optmized

Optimization and Exception Handling

Refine Source Code for singular bank account program.

Look for code optimization conventions and syntax.

Catch all Exceptions generated during program run-time. The program should never exit with error message.

Bank Account Program

Create an Account Class

We are forming the skeleton of a more complex bank account program.

Create instance variables for balance.You may need more depending on how you implement your bank account program. (We will continue to update the program as the semester continues.)

Create an 2 arrays as a members of the class.

Deposit_Array

Withdraw_Array

We will need methods:

Method for Depositing values into the account.

What type of method will it be?

Method for Withdrawing values from the account.

What type of method will it be?

Method to output the balance of the account.

What type of method will it be?

Method that will output all deposits made to the account.

Method that will output all withdraws made from the account.

Add a new method that will output the contents of the bank account program to a text file.

Program will output the balance of the account.

Program will output the account withdrawals.

Program will output the account deposits.

Use class constructor to initialize values in programmer class for program execution.

Balance Value

Withdrawal History

Deposit History

Output should be like

**************************************

* Bank Account Program: *

* Enter # to run program or Quit *

* 1) Make a Deposit *

* 2) Make a Withdrawal *

* 3) Output balance *

* 4) Output all deposits *

* 5) Output all withdrawals *

* 6) Quit *

**************************************

This is the code that need to be optimized.

import java.io.*; import java.util.*;

class Account{

private ArrayList Deposit; private ArrayList Withdrawl; private double balance; public Account(){ balance = 0; Deposit = new ArrayList(); Withdrawl = new ArrayList(); } public void withdrawl(double a){ if (balance >= a){ balance = balance - a; String str = "Withdrawl amount :" + Double.toString(a); Withdrawl.add(str); } else { System.out.println("Insufficient fund"); } } public void deposit(double a){ balance = balance + a; String str = "Deposit amount :" + Double.toString(a); Deposit.add(str); } public double getBalance(){ return balance; } public ArrayList getAllDeposits(){ return Deposit; } public ArrayList getAllWitdrawls(){ return Withdrawl; } public void outputToFile(){ Scanner sc = new Scanner(System.in); System.out.println("Enter filename:"); String name = sc.nextLine(); try { FileOutputStream fout = new FileOutputStream(name); PrintStream pw = new PrintStream(fout); pw.println("Balance:" + balance); for (int i = 0; i

}

public class Demo100{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); Account acc = new Account(); while (true){ System.out.println("1.Make a deposit"); System.out.println("2.Make a withdrawl"); System.out.println("3.Output balance"); System.out.println("4.Output all deposits"); System.out.println("5.Output all withdrawls"); System.out.println("6.Quit"); System.out.println("Enter option: "); int ch = Integer.parseInt(sc.nextLine()); if (ch == 6) break; if (ch == 1){ System.out.println("Enter deposit amount :"); double amt = Double.parseDouble(sc.nextLine()); acc.deposit(amt); } if (ch == 2){ System.out.println("Enter withdrwal amount :"); double amt = Double.parseDouble(sc.nextLine()); acc.withdrawl(amt); } if (ch == 3){ System.out.printf("Account Balance : %.2f", acc.getBalance()); System.out.println(); } if (ch == 4){ ArrayList list = acc.getAllDeposits(); for (int i = 0; i list = acc.getAllWitdrawls(); for (int i = 0; i

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions