helli everyone!!...hope your all in good health...jus wondered if someone could please help me...when i try to compile this code, it says "class or interface expected" for public Bank(String bankName)
i have tried, unsucessfully, to fix this but i dont understand what i have to do.... please can someone help as any help would be greatly appreciated.

public class Bank
{

private String bankName;
private Vector <BankAccount> bankAccounts = new Vector<BankAccount>();

/**
* Constructor for objects of class Bank.
* Newly created banks contain no accounts.
*/
public Bank(String bankName)
{
this.bankName = bankName;
}

public String getBankName()
{
return bankName;
}

/**
* Open a new bank account and return its account number.
* Account numbers are assigned to new accounts automatically:
* the first account created has account number "1", the second
* has account number "2", and so on.
*/
public String openNewAccount(String ownerName, double initialBalance, double overdraftLimit)
{
BankAccount newAccount = new BankAccount(ownerName, initialBalance, overdraftLimit);
bankAccounts.add(newAccount);
return newAccount.getAccountNumber();
}

/**
* If the account exists and has a zero balance,
* remove it from the bank. If it does not exist, or
* does exist but has a non-zero balance, do nothing.
* Note that removing an account has NO effect on the
* account numbers of other accounts, or on the
* automatically allocated account numbers for new
* accounts.
*
* @param accountNumber the account number to remove
*/
public void closeAccount(String accountNumber)
{
for(int i = 0; i < bankAccounts.size(); i++)
{
if(bankAccounts.get(i).getAccountNumber().equals(accountNumber))
{
bankAccounts.remove(i);
break;
}
}
}

/**
* The bank account with the given account number, or null
* if no such account exists.
*
* @param accountNumber the account number
*/
public BankAccount getAccount(String accountNumber)
{
for(int i = 0; i < bankAccounts.size(); i++)
{
if(bankAccounts.get(i).getAccountNumber().equals(accountNumber))
return bankAccounts.get(i);
}

return null;
}

/**
* The value of the total debt of all overdrawn accounts.
* For example, when the bank contains four accounts, with balances
* of 99, -20, -230, 0 then this method returns 250.
*/
public double totalDebt()
{
double debt = 0;

for(int i = 0; i < bankAccounts.size(); i++)
{
if(bankAccounts.get(i).getBalance() < 0)
debt += bankAccounts.get(i).getBalance();
}
return Math.abs(debt);
}

/**
* Print a list of the account numbers and account details
* for all accounts.
*/
public void printAccounts()
{
for(int i = 0; i < bankAccounts.size(); i++)
{
System.out.println("Account Number: " + bankAccounts.get(i).getAccountNumber());
System.out.println("Owner: " + bankAccounts.get(i).getOwnerName());
System.out.println("Balance: " + bankAccounts.get(i).getBalance());
System.out.println("Overdraft Limit: " + bankAccounts.get(i).getOverdraftLimit());
System.out.println("............................................");
}
}

/**
* The total number of accounts in this bank.
*/
public int size()
{
return bankAccounts.size();
}
}


Thank you :D

Member Avatar for Dukane

Problem #1: You don't import the Vector class.

hi, thanks for your help

i have put this,
import java.util.Vector;

i have now been tryin(unsucessfully) to fix this code for 4 horus straight....pleassseee can someone help...i cannot compile it!!:eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek::eek:
it is now 1:26am in england and my eyes are dropping but i need this for tomorro

thanks prblem solved

/**
* If the given account exists, return its current balance,
* otherwise return 0.
*
* @param accountNumber the account number
*/
public int getUserBalance(String accountNumber);

BankAccount account = bank.getAccount(accountNumber);
if (availableFunds < amount) {
System.out.println("You have insufficient funds.");
} else if (reserves() == 0) {
System.out.println("This machine is empty.");
}


i do not understand y this doesnt compile...pleas help...it ses illegal start of type???
thanks

I'm guessing it would be the semi-colon at the end of the function declaration. Remove that and see if it works... though your method should be contained within curly braces {} too...

thnaks very much..now it says } needed...thank you for your help!!

its really helped its almost 2:13am nd my eyes are dropping but i have to get this done...noooooo!!
:)

i was wondering if you could please point me in the directiion of how to solve the following:

public class CashMachine
{
/** The bank. */
private Bank bank;

/** Number of twenty pound notes in machine. */
private int twenties;

/** Number of ten pound notes in machine. */
private int tens;

/** Number of five pound notes in machine. */
private int fives;

/** Was the last request for cash successful? */
private boolean lastRequestOK;

/**
* Constructor for objects of class CashMachine.
* Newly created machines contain no bank notes.
*
* @param bank the bank to which this machine is connected
*/
public CashMachine(Bank bank)
{
this.bank = bank;
twenties = 0;
tens = 0;
fives = 0;
lastRequestOK = true;
}

/**
* Add some twenty pound notes to the machine's reserves.
*
* @param n the number of notes to add
*/
public void addTwenties(int n)
{
twenties += n;
}

/**
* Add some ten pound notes to the machine's reserves.
*
* @param n the number of notes to add
*/
public void addTens(int n)
{
tens += n;
}

/**
* Add some five pound notes to the machine's reserves.
*
* @param n the number of notes to add
*/
public void addFives(int n)
{
fives += n;
}

/**
* If the given account exists, return its current balance,
* otherwise return 0.
*
* @param accountNumber the account number
*/
public int getUserBalance(String accountNumber)
{
BankAccount account = bank.getAccount(accountNumber);
// YOUR CODE GOES HERE
return -1; // replace this with something sensible
}

I have been stuglling with this for 4 hours and it is now 3:42am here and i have to hand this in in 5 hours. Please can you help with writing the code??

thank you VERY much

Ok, I just looked over the code real quick, and one question really stands out: what does the BankAccount class have for methods? I'd assume there's going to be a getBalance() or somesuch, in which case you can just return that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.