package account; import java.text.*; public class Account { private String personName; private String accountNumber; private double currentBalance; private double totalDeposits; private double totalWithdrawals; private int numberDeposits; private int numberWithdrawals; public Account(String name, String accountID) { this(name, accountID, 0.0); } public Account(String name, String accountID, double balance) { personName = name; accountNumber = accountID; if (balance < 0) currentBalance = 0.0; else currentBalance = balance; totalDeposits = 0.0; totalWithdrawals = 0.0; numberWithdrawals = 0; if (currentBalance > 0.0) numberDeposits = 1; else numberDeposits = 0; } public boolean deposit(double amount) { if (amount < 0.0) return false; currentBalance += amount; totalDeposits += amount; numberDeposits++; return true; } public double getCurrentBalance() { return currentBalance; } public int getNumberDeposits() { return numberDeposits; } public int getNumberWithdrawals() { return numberWithdrawals; } public double getTotalDeposits() { return totalDeposits; } public double getTotalWithdrawals() { return totalWithdrawals; } public boolean withdraw(double amount) { if (amount < 0 || amount > currentBalance) return false; currentBalance -= amount; totalWithdrawals += amount; numberWithdrawals++; return true; } public void printStatement() { DecimalFormat form = new DecimalFormat("0.00"); System.out.println("---------------------------"); System.out.println("Account number: " + accountNumber); System.out.println("Account holder: " + personName); System.out.println("Current balance: $ " + form.format(currentBalance)); System.out.println("Total deposits: $ " + form.format(totalDeposits)); System.out.println("Number deposits: " + numberDeposits); System.out.println("Total withdrawals: $ " + form.format(totalWithdrawals)); System.out.println("Number deposits: " + numberWithdrawals); System.out.println("-----------------------------"); } public void reset() { totalDeposits = 0.0; totalWithdrawals = 0.0; numberWithdrawals = 0; numberDeposits = 0; } public String toString() { return getClass().getName() + "[name=" + personName + ",number=" + accountNumber + ",balance=" + currentBalance + ",deposits=" + totalDeposits + ",withdrawals=" + totalWithdrawals + ",number withdrawals=" + numberWithdrawals + ",number deposits=" + numberDeposits; } }