"Write a Java class, Bank.java, that implements a bank as an ArrayList of Account objects. The Bank object should have a field, nextAccount, initialized to 101. There is a method, addAccount(String name, double balan), that accepts a name and an initial balance as parameters. As each account is added, it is given the value in nextAccount, which is then incremented. Every account is given the interest rate, 3.5%."
The error I’m having is listed in the code. I am not sure what to do here.
account class
public class Account
{
private int accountNumber;
private String ownersName;
private double interestRate;
private double balance;
public Account(int aNum, String oName, double iRate, double bal)
{
accountNumber = aNum;
ownersName = oName;
interestRate = iRate;
if(bal < 0.0)
{
balance = 0.0;
}
else
{
balance = bal;
}
}
public int getAccountNumber()
{
return accountNumber;
}
public String getOwnersName()
{
return ownersName;
}
public double getInterestRate()
{
return interestRate;
}
public double getBalance()
{
return balance;
}
public void setOwnersName(String newOwnersName)
{
ownersName = newOwnersName;
}
public void setInterestRate(double newInterestRate)
{
interestRate = newInterestRate;
}
public void deposit(double amt)
{
if(amt > 0.0)
{
balance = balance + amt;
}
else
{
balance = balance;
}
}
public void withdraw(double amt)
{
if(amt > 0.0)
{
balance = balance - amt;
}
else
{
balance = balance;
}
}
public void addInterest()
{
balance = balance + (balance * (interestRate / 100));
}
public void print()
{
System.out.println("Account Number: " + accountNumber);
System.out.println("Owners Name: " + ownersName);
System.out.println("Interest Rate: " + interestRate);
System.out.println("Balance: " + balance);
}
}
bank class
import java.util.*;
public class Bank
{
private int nextAccount;
private ArrayList<Account> accounts;
public Bank()
{
nextAccount = 101;
accounts = new ArrayList<Account>();
}
public void addAccount(String name, double balan)
{
accounts.add(new Account(int aNum, String oName, double iRate, double bal)); // error: “.class expected”
bal = balan;
oName = name;
aNum = nextAccount;
iRate = .035;
nextAccount++;
}
}
This post has been edited by mattlyons: 08 October 2009 - 08:49 PM

New Topic/Question
Reply




MultiQuote







|