Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This Exercise contains a SavingsTest and a Savings class. The SavingsTest class makes deposits and withdrawals from the Savings class, then reports the balance and

This Exercise contains a SavingsTest and a Savings class. The SavingsTest class makes deposits and withdrawals from the Savings class, then reports the balance and transactions. The Savings class has a balance data field and transaction ArrayList. You will need to: 1. Create the Constructors for the Savings class 2. Write the code for the withdraw() method. 3. Create a get and set method for the balance class 4. Understand how everything works in these classes. Example Output 88.54 deposited 23.98 withdrawn 88.34 deposited 144.98 withdrawn Ending Account Balance: $107.92 88.54 deposited, the new balance is $188.54 23.98 withdrawn, the new balance is $164.56 88.34 deposited, the new balance is $252.90 144.98 withdrawn, the new balance is $107.92

What I have so far:

import java.util.*; /** * * @author Student */ public class SavingsTest {

public static void main(String[] args) { Savings savings = new Savings(100.00); // this calls a method called deposit that adds to the savings balance System.out.println(savings.deposit(88.54)); // this calls a method called withdraw that subtracts from the balance System.out.println(savings.withdraw(23.98)); // more transactions System.out.println(savings.deposit(88.34)); System.out.println(savings.withdraw(144.98)); // generate output for the account balances System.out.printf(" Ending Account Balance: $%.2f ",savings.getBalance()); System.out.println(savings.getStatement()); } // end main method } // end SavingsTest class

//****************************************** //** Savings class below this box ** //******************************************

class Savings { private double balance; private ArrayList transaction = new ArrayList();

//*** create constructors here ****

public String deposit(double input){ balance += input; transaction.add(String.format("%.2f deposited, the new balance is $%.2f", input,balance)); return String.format("%.2f deposited",input); } public String getStatement(){ String returnStr =""; for(String trans:transaction){ returnStr += trans + " "; } return returnStr; }

public String withdraw(double input){ balance -= input; transaction.add(String.format("%.2f withdrawn, the new balance is $%.2f", input,balance)); return String.format("%.2f withdrawn",input); } // GETTER AND SETTER public void setBalance(double balance){ this.balance = balance; } public double getBalance(){ return balance; } }

// Enter gets and sets for the balance data field

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

Students also viewed these Databases questions