import java.util.Date;
import java.util.ArrayList;
public class NewAccountClass {
public static void main(String[] args) {
//create an instance object of class Account
Account myAccount = new Account(0.015, 1000.00, 1122, "George");
myAccount.deposit(30.00);
myAccount.deposit(40.00);
myAccount.deposit(50.00);
myAccount.withdraw(5.00);
myAccount.withdraw(4.00);
myAccount.withdraw(2.00);
//display account holder name, interest rate, balance and all transactions
System.out.println("Account Holder Name: " + myAccount.name);
System.out.println("Monthly Interest: " + myAccount.getMonthlyInterestRate());
System.out.println("Balance: " + myAccount.balance);
java.util.ArrayList transactions = new java.util.ArrayList();
System.out.println(transactions.toString());
}
}
class Account {
//define var1, var2
int id;
double balance;
double annualInterestRate;
Date dateCreated = new Date();
String name;
ArrayList transactions = new ArrayList();
//no arg constructer
Account() {
id = 0;
balance = 0.0;
annualInterestRate = 0.0;
}
//constructor with specific id and initial balance
Account(int newId, double newBalance) {
id = newId;
balance = newBalance;
}
Account(int newId, double newBalance, double newAnnualInterestRate) {
id = newId;
balance = newBalance;
annualInterestRate = newAnnualInterestRate;
}
Account(String newName, int newId, double newBalance) {
name = newName;
id = newId;
balance = newBalance;
}
Account(double newAnnualInterestRate, double newBalance, int newId, String newName) {
annualInterestRate = newAnnualInterestRate;
balance = newBalance;
id = newId;
name = newName;
}
//accessor/mutator methods for id, balance, and annualInterestRate
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int newId) {
id = newId;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public void setAnnualInterestRate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
//accessor method for dateCreated
public void setDateCreated(Date newDateCreated) {
dateCreated = newDateCreated;
}
//define method getMonthlyInterestRate
double getMonthlyInterestRate() {
return annualInterestRate/12;
}
//define method withdraw
double withdraw(double amount) {
balance -= amount;
Transaction transaction = new Transaction(dateCreated, 'W', balance, "withdrawal made");
transactions.add(transaction);
return balance;
}
//define method deposit
double deposit(double amount) {
balance += amount;
Transaction transaction = new Transaction(dateCreated, 'D', balance, "deposit made");
transactions.add(transaction);
return balance;
}
}
class Transaction {
//define variables
Date dateTransaction;
char type;
double amount;
double balance;
String description;
ArrayList transactions = new ArrayList();
//constructor with specific date, type, balance, and description
Transaction(Date newDateTransaction, char newType, double newBalance, String newDescription) {
dateTransaction = newDateTransaction;
type = newType;
balance = newBalance;
description = newDescription;
}
public String toString() {
for (int i = 0; i < transactions.size(); i++) {
System.out.println(transactions.get(i));
}
return "Transactions: " + transactions;
}
}