This is for addnew account.
private void btnSaveAActionPerformed(java.awt.event.ActionEvent evt)
{
BankAccount account = new BankAccount();
ButtonGroup bg = new ButtonGroup();
bg.add(rad_savings);
bg.add(rad_checking);
account.setAccountName(txt_accountname.getText());
account.setAccountNo(txt_accountnumber.getText());
account.setBalance(Double.parseDouble(txt_initialbalance.getText()));
list.add(account);
if(rad_savings.isSelected()){
//account = new SavingsAccount();
account.setAccountType("Savings");
list.add(account);
}
else
{
//account = new CheckingAccount();
account.setAccountType("Checking");
list.add(account);
}
}
I also have, Savings and Checkings Class
Savings:
public class SavingsAccount extends BankAccount {
public SavingsAccount(){
};
public SavingsAccount(String accountNo, String accountName, double initBalance) {
super(accountNo, accountName, initBalance);
}
public SavingsAccount(String accountNo, String accountName) {
super(accountNo, accountName);
}
}
Checking:
public class CheckingAccount extends BankAccount {
private double overdraftProtection;
public CheckingAccount(){
};
public CheckingAccount(String accountNo, String accountName,
double initBalance) {
super(accountNo, accountName, initBalance);
}
public CheckingAccount(String accountNo, String accountName) {
super(accountNo, accountName);
}
public double getOverdraftProtection() {
return overdraftProtection;
}
public void setOverdraftProtection(double overdraftProtection) {
this.overdraftProtection = overdraftProtection;
}
public void withdraw(double amount) {
// TODO: code for withdrawal
}
}
In my BankAccount Class, i have this:
public class BankAccount {
private String accountNo;
private String accountName;
protected double balance;
private String accountType;
public String toString(){
return "Account name: " + accountName + "" + System.getProperty("line.separator") +
"Account Number: " + accountNo + "" +System.getProperty("line.separator")+
"Balance: " + balance + "" + System.getProperty("line.separator")+
"Account Type: " + accountType;
}
When I'm trying it, it replicates the set the of data:
For example: I've entered Account Name: John, Account No: 101, Initial Balance: 500, Account Type: Savings.
It will output like this:
Account Name: John
Account No: 101
Initial Balance: 500
Account Type: Savings
Account Name: John
Account No: 101
Initial Balance: 500
Account Type: Savings
I can't find what is wrong.
In btnSaveAActionPerformed you call list.add(account); and then check whether the account is a checking or savings account. In the if statements of both of those you do another list.add(account);
This is causing the double addition of the account.
**code is the cause of your problem as you are adding the account object twice in the list.
**list.add(account);**
if(rad_savings.isSelected()){
//account = new SavingsAccount();
account.setAccountType("Savings");
**list.add(account);**
}
else
{
//account = new CheckingAccount();
account.setAccountType("Checking");
**list.add(account);**
}
Update your code like this:
if(rad_savings.isSelected()){
//account = new SavingsAccount();
account.setAccountType("Savings");
}
else
{
//account = new CheckingAccount();
account.setAccountType("Checking");
}
list.add(account);
Related
I have one abstract class Account and one subclass SavingsAccount, but when I create SavingsAccount object it doesn't assign a number like 1001, 1002, 1003 and so on. Any idea why?
import java.util.ArrayList;
public abstract class Account {
private String accountType;
private static double balance = 0;
private static int accountId;
private static int accountNumberCounter = 1000;
private ArrayList<Account> accounts;
public Account(String acType, int acNumber){
accountType = acType;
accountNumberCounter ++;
accountId = accountNumberCounter;
}
public Account() {
accountNumberCounter++;
accountId = accountNumberCounter;
}
public void addAccounts(Account acc){
accounts.add(acc);
}
public void deposit(double amount){
balance += amount;
}
public abstract boolean withdraw(double value);
public String getAccountInfo(){
return "Account type: " + accountType + ", Account number: " + accountId;
}
public int getAccountNumber(){
return accountId;
}
public String getAccount(){
String accountInformation = "Account Number: : " + accountId + "\nAccount Type: " + accountType;
return accountInformation;
}
public void closeCurrentAccount() {
if (balance < 0) {
System.out.println("Your balance: " + balance + "Close your debt");
} else {
System.out.println("Ending balance: " + balance);
}
}
}
And this is SavingsAccount
public class SavingsAccount extends Account {
private static double balance = 0;
private static final double RATE = 1.0;
private static String accountType = "Savings Account";
private static int accountId;
public SavingsAccount(){
super();
}
public double getBalance(){
return balance;
}
public void deposit(double amount){
balance = balance + amount;
}
public boolean withdraw(double amount){
if (balance<= amount){
System.out.println("You have only" + amount + "left on your account.");
return false;
}
else{
balance -= amount;
System.out.println("You put:" + amount);
return true;
}
}
public static String getAccountType(){
return accountType;
}
public static double getRate(){
return RATE;
}
public static double calculateRate(){
return balance += (balance * RATE) / 100;
}
public String getAccount(){
String accountInformation = "Account Number: : " + accountId + "\nAccount Type: " + accountType +
"\nBalance: " + balance + "\nRate: " + RATE;
return accountInformation;
}
}
Maybe it's not needed but here is Customer class as well
import java.util.ArrayList;
public class Customer {
private String name;
private String surname;
private String personalNumber;
private ArrayList<Account> accounts;
public Customer(String customerName, String customerSurname, String customerPersonalNumber)
{
name = customerName;
surname = customerSurname;
personalNumber = customerPersonalNumber;
this.accounts = new ArrayList<Account>();
}
public Customer(){
}
public String getName(){
return name;
}
public String getSurname(){
return surname;
}
public String getPersonalNumber(){
return personalNumber;
}
public void setName(String aName){
name = aName;
}
public void setSurname(String aSurname){
surname = aSurname;
}
public void setPersonalNumber(String aPersonalNumber){
personalNumber = aPersonalNumber;
}
public void addAccounts(Account acc){
accounts.add(acc);
}
public String getCustomerInfo(){
return name + " " + surname + " " + personalNumber;
}
public int getFirstAccountNumber(){
return accounts.get(0).getAccountNumber();
}
public int getLastAccountNumber(){
return accounts.get(accounts.size()-1).getAccountNumber();
}
public ArrayList<Account> getAllAccounts(){
return accounts;
}
}
When I do some tests this unique number doesn't get assigned.
Is it something wrong with a constructor?
You marked accountId as static as well, so every instance of Account will acquire the same id, that is the latest you "generated".
Just mark accountId as a normal instance variable (i.e., remove static).
As a side note, re-declaring accountId in SavingsAccount breaks encapsulation and is, frankly, weird. You inherited getAccountNumber() from Account. Use that instead of accessing accountId directly. You're treating it as a read-only variable anyway.
So I'm supposed to design and implement an ADT that represents a credit card. It should include customer name, account number, due date, reward points, and account balance. There should be operations for a credit card charge, a cash advance, a payment, the addition of interest to the balance, and the display of the statistics of the bank account. However when I run my program,
I keep getting an error saying "Class "creditCard" does not have a main method."
import java.util.Scanner;
import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
public class creditCard {
private int customerName;
private int accountNumber;
private int dueDate;
private int rewardPoints;
private int accountBalance;
static Scanner input = new Scanner(System.in);
double creditLimit = 500;
int user = 0;
public int getCustomerName() {
return customerName;
}
public void setCustomerName(int customerName) {
this.customerName = customerName;
}
public int getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(int accountNumber) {
this.accountNumber = accountNumber;
}
public int getDueDate() {
return dueDate;
}
public void setDueDate(int dueDate) {
this.dueDate = dueDate;
}
public int getRewardPoints() {
return rewardPoints;
}
public void setRewardPoints(int rewardPoints) {
this.rewardPoints = rewardPoints;
}
public int getAccountBalance() {
return accountBalance;
}
public void setAccountBalance(int accountBalance) {
this.accountBalance = accountBalance;
}
public String charge(float amount) {
if (amount > creditLimit) {
System.out.println("You have exceeded your credit card limit and no charge can be made");
}
if (creditLimit - amount > 0) {
System.out.println("You have exceeded your credit card limit and no charge can be made");
}
creditLimit = creditLimit - amount;
System.out.println("A charge of" + amount + "has been made.");
String charge = "A charge of" + amount + "has been made.";
return charge;
}
public String advance(float amount) {
if (amount > creditLimit) {
System.out.println("You have exceeded your credit card limit and no charge can be made");
}
if (creditLimit - amount > 0) {
System.out.println("You have exceeded your credit card limit and no charge can be made");
}
creditLimit = creditLimit - amount;
System.out.println("You have withdrawn $ " + amount);
String advance = "You have withdrawn $ " + amount;
return advance;
}
public String payment(float amount) {
creditLimit = creditLimit + amount;
System.out.println("You have a credit limit of $ " + creditLimit);
String payment = "You have a credit limit of $ " + creditLimit;
return payment;
}
public String interest() {
creditLimit = (creditLimit * 0.02) + creditLimit;
String interest = "An interest of" + creditLimit * 0.02 + "has been added to your balance";
return interest;
}
public void statistics(String charge, String advance, String payment, String interest) {
System.out.println(charge);
System.out.println(advance);
System.out.println(payment);
System.out.println(interest);
}
public void showMenu() {
while (user!= 5) {
System.out.println("Choose Charge(1) \nAdvance(2) \nPayment(3) \nInterest(4) \ncStatistics(5)");
user = input.nextInt();
switch (user) {
case 1:
float amount;
System.out.println("Enter the amount: ");
amount = input.nextFloat();
String charge = charge(amount);
break;
case 2:
float withdrawalAmount;
System.out.println("Enter amount to withdraw: ");
withdrawalAmount = input.nextFloat();
String advance = advance(withdrawalAmount);
break;
case 3:
float paymentAmount;
System.out.println("Enter payment.");
paymentAmount = input.nextFloat();
String payment = payment(paymentAmount);
break;
case 4:
String interest = interest();
break;
//case 5:
//statistics(charge, advance, payment, interest);
//break;
}
}
}
public void main(String[] args) {
showMenu();
}
}
make the main method static.
public static void main(String[] args) {
showMenu();
}
or better create another entry point class and put your main there.
public class Runner {
public static void main(String[] args) {
CreditCard creditCard= new CreditCard();
creditCard.showMenu();
// Do something else
}
I have two objects derived from an Account class stored in an ArrayList. I am trying to call overridden methods with a basic for loop but I can't get it to work consistently.
import java.util.ArrayList;
import java.util.Scanner;
public class InheritanceTest
{
private static class Account
{
//Constructor
Account()
{
}
private void processDeposit()
{
double deposit = 0;
System.out.println("Please enter the deposit amount: ");
deposit = input.nextDouble();
balance += deposit;
}
private void processWithdrawal()
{
double withdrawal = 0;
System.out.println("Please enter the amount to be drawn from the account: ");
withdrawal = input.nextDouble();
balance -= withdrawal;
}
public String getAccountName() {
System.out.println("Creating " + "account, enter name: ");
accountName = input.nextLine();
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public int getAcctID() {
System.out.println("Your " + "account number is " + acctID);
return acctID;
}
public void setAcctID(int acctID) {
this.acctID = acctID;
acctID++;
}
}
//
private static class CheckingAccount extends Account
{
public String getAccountName() {
System.out.println("Creating checking account, enter name: ");
accountName = input.nextLine();
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
private void processWithdrawal()
{
double withdrawal = 0;
System.out.println("Please enter the amount to be drawn from the account: ");
withdrawal = input.nextDouble();
if (withdrawal > balance)
{
balance -= 10;
System.out.println("Overdraft fee has been charged");
} else
balance -= withdrawal;
}
}
//
private static class SavingsAccount extends Account
{
public String getAccountName() {
System.out.println("Creating savings account, enter name: ");
accountName = input.nextLine();
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
private void processWithdrawal()
{
double withdrawal = 0;
System.out.println("Please enter the amount to be drawn from the account: ");
withdrawal = input.nextDouble();
if(withdrawal > balance)
{
System.out.println("Insufficient funds");
} else
{
balance -= withdrawal;
}
}
}
//
public static void main(String[] args)
{
ArrayList<Account> Bank = new ArrayList<Account>();
CheckingAccount checking1 = new CheckingAccount();
Bank.add(checking1);
SavingsAccount savings = new SavingsAccount();
Bank.add(savings);
for(int i = 0; i<Bank.size(); i++)
{
Bank.get(i).getAccountName();
Bank.get(i).setAccountName(Bank.get(i).accountName);
Bank.get(i).getAcctID();
Bank.get(i).setAcctID(Bank.get(i).acctID);
}
for (int i =0; i<Bank.size(); i++)
{
System.out.println("Processing Account: " + Bank.get(i).acctID);
Bank.get(i).processDeposit();
System.out.println("Balance: " + Bank.get(i).balance);
Bank.get(i).processWithdrawal();
System.out.println("Balance: " + Bank.get(i).balance);
Bank.get(i).processWithdrawal();
Bank.get(i).displayAccount(Bank.get(i).acctID, Bank.get(i).accountName, Bank.get(i).balance);
}
}
}
The first loop calls the overridden getAccountName methods just fine, yet the second loop only seems to be calling the processWithdrawal method from the base class. Can anyone point me in the direction of finding out why this might be happening?
private void processWithdrawal()
make it public
public void processWithdrawal()
When you would like to override a method i.e. leverage the feature of Dynamic Polymorphism the method should be protected/public.
A private method is restricted only to that specific class in which it is declared which wouldnt make Overriding possible.
i have a program that create an array of Account object by asking the user to enter their properties than the system will make of these inserted input an array.
this is my code
Account.java
package question1;
import java.util.Date;
public class Account {
public int AccountNum;
public double BALANCE;
public Date OPENDATE;
public String OwnerName;
public Account() {
// TODO Auto-generated constructor stub
}
public Account(int accnum, double balance, Date opendate, String ownername) {
this.AccountNum = accnum;
this.BALANCE = balance;
this.OPENDATE = opendate;
this.OwnerName = ownername;
}
public int getAccountNum() {
return AccountNum;
}
public void setAccountNum(int accountNum) {
AccountNum = accountNum;
}
public double getBALANCE() {
return BALANCE;
}
public void setBALANCE(double bALANCE) {
BALANCE = bALANCE;
}
public Date getOPENDATE() {
return OPENDATE;
}
public void setOPENDATE(Date oPENDATE) {
OPENDATE = oPENDATE;
}
public String getOwnerName() {
return OwnerName;
}
public void setOwnerName(String ownerName) {
OwnerName = ownerName;
}
public double yearlyInterest(double balace) {
return balace;
}
}
Bank.java
package question1;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class Bank {
public static void main(String[] args) {
List<Account> accounts = new ArrayList<Account>(4);
Scanner sc = new Scanner(System.in);
while(!sc.hasNext()){
System.out.println("enter your balance");
int b = sc.nextInt();
System.out.println("enter your name");
String s = sc.nextLine();
}
}
}
i do not know how to continue in the Bank Class and how to create this array using the scanner.
if anyone can help me i will appreciate this.
You can do something like this
Scanner scanner = new Scanner(System.in);
System.out.println("Do you wanna create new account?Y/N");
while(scanner.next().equalsIgnoreCase("y")){
//Get needed information. You shouldn't take account number from user. It must be generated
System.out.println("Enter Name");
String name = scanner.next();
System.out.println("Enter Account Balance");
float balance = scanner.nextFloat();
......
//create new instance of Account and set values
Account acc = new Account();
acc.setBalance(balance);
.....
//add instance to list
accounts.add(acc);
System.out.println("Do you wanna create new account?Y/N");
}
I think you are studying for the exams of Lebanese army LOL anw this is the code bro.
AccountDriver
//Demonstrates the BankAccount and derived classes
import java.text.*; // to use Decimal Format
public class AccountDriver
{
public static void main(String[] args)
{
double put_in = 500;
double take_out = 1000;
DecimalFormat myFormat;
String money;
String money_in;
String money_out;
boolean completed;
// to get 2 decimals every time
myFormat = new DecimalFormat("#.00");
//to test the Checking Account class
CheckingAccount myCheckingAccount =
new CheckingAccount ("Benjamin Franklin", 1000);
System.out.println ("Account Number "
+ myCheckingAccount.getAccountNumber() +
" belonging to " + myCheckingAccount.getOwner());
money = myFormat.format(myCheckingAccount.getBalance());
System.out.println ("Initial balance = $" + money);
myCheckingAccount.deposit (put_in);
money_in = myFormat.format(put_in);
money = myFormat.format(myCheckingAccount.getBalance());
System.out.println ("After deposit of $" + money_in
+ ", balance = $" + money);
completed = myCheckingAccount.withdraw(take_out);
money_out = myFormat.format(take_out);
money = myFormat.format(myCheckingAccount.getBalance());
if (completed)
{
System.out.println ("After withdrawal of $" + money_out
+ ", balance = $" + money);
}
else
{
System.out.println ("Insuffient funds to withdraw $"
+ money_out + ", balance = $" + money);
}
System.out.println();
//to test the savings account class
SavingsAccount yourAccount =
new SavingsAccount ("William Shakespeare", 400);
System.out.println ("Account Number "
+ yourAccount.getAccountNumber() +
" belonging to " + yourAccount.getOwner());
money = myFormat.format(yourAccount.getBalance());
System.out.println ("Initial balance = $" + money);
yourAccount.deposit (put_in);
money_in = myFormat.format(put_in);
money = myFormat.format(yourAccount.getBalance());
System.out.println ("After deposit of $" + money_in
+ ", balance = $" + money);
completed = yourAccount.withdraw(take_out);
money_out = myFormat.format(take_out);
money = myFormat.format(yourAccount.getBalance());
if (completed)
{
System.out.println ("After withdrawal of $" + money_out
+ ", balance = $" + money);
}
else
{
System.out.println ("Insuffient funds to withdraw $"
+ money_out + ", balance = $" + money);
}
yourAccount.postInterest();
money = myFormat.format(yourAccount.getBalance());
System.out.println ("After monthly interest has been posted,"
+ "balance = $" + money);
System.out.println();
// to test the copy constructor of the savings account class
SavingsAccount secondAccount =
new SavingsAccount (yourAccount,5);
System.out.println ("Account Number "
+ secondAccount.getAccountNumber()+
" belonging to " + secondAccount.getOwner());
money = myFormat.format(secondAccount.getBalance());
System.out.println ("Initial balance = $" + money);
secondAccount.deposit (put_in);
money_in = myFormat.format(put_in);
money = myFormat.format(secondAccount.getBalance());
System.out.println ("After deposit of $" + money_in
+ ", balance = $" + money);
secondAccount.withdraw(take_out);
money_out = myFormat.format(take_out);
money = myFormat.format(secondAccount.getBalance());
if (completed)
{
System.out.println ("After withdrawal of $" + money_out
+ ", balance = $" + money);
}
else
{
System.out.println ("Insuffient funds to withdraw $"
+ money_out + ", balance = $" + money);
}
System.out.println();
//to test to make sure new accounts are numbered correctly
CheckingAccount yourCheckingAccount =
new CheckingAccount ("Issac Newton", 5000);
System.out.println ("Account Number "
+ yourCheckingAccount.getAccountNumber()
+ " belonging to "
+ yourCheckingAccount.getOwner());
}
}
BankAccount(Parent class)
//Defines any type of bank account
public abstract class BankAccount
{
// class variable so that each account has a unique number
protected static int numberOfAccounts = 100001;
// current balance in the account
private double balance;
// name on the account
private String owner;
// number bank uses to identify account
private String accountNumber;
//default constructor
public BankAccount()
{
balance = 0;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}
//standard constructor
public BankAccount(String name, double amount)
{
owner = name;
balance = amount;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}
//copy constructor
public BankAccount(BankAccount oldAccount, double amount)
{
owner = oldAccount.owner;
balance = amount;
accountNumber = oldAccount.accountNumber;
}
//allows you to add money to the account
public void deposit(double amount)
{
balance = balance + amount;
}
//allows you to remove money from the account if
//enough money is available
//returns true if the transaction was completed
//returns false if the there was not enough money
public boolean withdraw(double amount)
{
boolean completed = true;
if (amount <= balance)
{
balance = balance - amount;
}
else
{
completed = false;
}
return completed;
}
//accessor method to balance
public double getBalance()
{
return balance;
}
//accessor method to owner
public String getOwner()
{
return owner;
}
//accessor method to account number
public String getAccountNumber()
{
return accountNumber;
}
//mutator method to change the balance
public void setBalance(double newBalance)
{
balance = newBalance;
}
//mutator method to change the account number
public void setAccountNumber(String newAccountNumber)
{
accountNumber = newAccountNumber;
}
}
CheckingAccount
public class CheckingAccount extends BankAccount {
private double fee = .15;
private String accountNumber = getAccountNumber() + "-10";
public CheckingAccount(String name, double amount)
{
super(name, amount);
setAccountNumber(accountNumber);
}
public boolean withdraw(double amount)
{
double finalAmount = amount + fee;
super.withdraw(finalAmount);
boolean completed = true;
return completed;
}
}
And finally, SavingsAccount
public class SavingsAccount extends BankAccount{
double rate = .025;
static int savingsNumber = 0;
private String accountNumber = super.getAccountNumber();
//Default constructor
public SavingsAccount(String name, double amount){
super(name, amount);
accountNumber = accountNumber + "-" + Integer.toString(savingsNumber);
}
//Copy constructor
public SavingsAccount(SavingsAccount oldAccount, double amount)
{
savingsNumber++;
accountNumber = oldAccount.accountNumber + Integer.toString(savingsNumber);
owner = oldAccount.getOwner();
balance = oldAccount.getBalance();
}
public void postInterest(){
double interestAmount = getBalance() * .025/12;
double finalAmount = getBalance() + interestAmount;
setBalance(finalAmount);
}
public String getAccountNumber()
{
return accountNumber;
}
}
I get this Exception when I try to create a new customer in my bank account program:
Exception in thread "main" java.lang.NullPointerException
at bank.program.Customer.addAccount(Customer.java:18)
at bank.program.BankProgram.main(BankProgram.java:24)
Java Result: 1
What does it mean, and what do I need to change to get rid of it?
Bank class:
public class Bank {
String bankName;
private ArrayList<Customer> customers = new ArrayList<Customer>();
Bank(String bankName) {
this.bankName = bankName;
}
public void addCustomer(Customer newCustomer) {
customers.add(newCustomer);
}
}
Account class:
public abstract class Account {
protected double balance = 0;
protected String accountId;
public Account() {} //Defaultkonstruktor
public Account(double bal, String id) { //Konstruktor
if (balance >= 0) {
balance = bal;
}
else {
balance = 0;
}
accountId = id;
}
public abstract void deposit(double amount);
public abstract void withdraw(double amount);
public abstract double getBalance();
public abstract String getAccountId();
public void transfer(double amount, Account account) {
account.deposit(amount);
balance -= amount;
}
}
SavingsAccount class:
public class SavingsAccount extends Account {
private double interest = 2.9;
public SavingsAccount() {
super();
}
public SavingsAccount(double bal, String id) {
super(bal, id);
}
#Override
public void deposit(double amount) {
}
#Override
public void withdraw(double amount) {
}
#Override
public double getBalance() {
}
#Override
public String getAccountId() {
}
}
Customer class:
public class Customer {
private String firstName;
private String lastName;
private String number;
private ArrayList<Account> accounts;
Customer(String firstName, String lastName, String number) {
this.firstName = firstName;
this.lastName = lastName;
this.number = number;
}
public void addAccount(SavingsAccount account) {
accounts.add(account);
}
public ArrayList<Account> getAccounts() {
return accounts;
}
}
Bank program class:
public class BankProgram {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numberOfCustomers = 0;
Bank bank = new Bank("Bank name");
System.out.print("Enter amount to deposit: ");
double amount = input.nextDouble();
System.out.println("Account number: " + numberOfCustomers);
System.out.print("First name: ");
String firstName = input.next();
System.out.print("Last name: ");
String lastName = input.next();
System.out.print("Customer number: ");
String pnumber = input.next();
Customer newCustomer = new Customer(firstName, lastName, pnumber);
SavingsAccount savingsAccount = new SavingsAccount(amount, "11");
newCustomer.addAccount(savingsAccount);
bank.addCustomer(newCustomer);
}
}
You're trying to add an account without initializing the ArrayList in which they're stored. Add this to your Customer constructor.
this.accounts = new ArrayList<Account>();
In your Customer class, you declare an ArrayList accounts. Then, you have a method called addAccount, but it seems as though this accounts was never initialized.
Somewhere where you create your Customer object, you need to say:
newCustomer.accounts = new ArrayList<Account>();