//*******************************************************
// Account.java
//
// A bank account class with methods to deposit to, withdraw from,
// change the name on, and get a String representation
// of the account.
//*******************************************************
public class Account
{
private double balance;
private String name;
private long acctNum;
private static int numAccounts = 0;
//----------------------------------------------
//Constructor -- initializes balance, owner, and account number
//----------------------------------------------
public Account(double balance, String name, long acctNum)
{
this.balance = balance;
this.name = name;
this.acctNum = acctNum;
numAccounts++;
}
//----------------------------------------------
// Checks to see if balance is sufficient for withdrawal.
// If so, decrements balance by amount; if not, prints message.
//----------------------------------------------
public void withdraw(double amount)
{
if (balance >= amount)
balance -= amount;
else
System.out.println("Insufficient funds");
}
//----------------------------------------------
// Adds deposit amount to balance.
//----------------------------------------------
public void deposit(double amount)
{
balance += amount;
}
//----------------------------------------------
// Returns balance.
//----------------------------------------------
public double getBalance()
{
return balance;
}
//----------------------------------------------
// Returns account number.
//----------------------------------------------
public long getAcctNumber()
{
return acctNum;
}
//----------------------------------------------
// Returns a string containing the name, account number, and balance.
//----------------------------------------------
public String toString()
{
return "Name: " + name +
"\nAccount Number: " + acctNum +
"\nBalance: " + balance;
}
//----------------------------------------------
//Returns Number of Accounts
//----------------------------------------------
private static int numAccounts()
{
numAccounts++;
return numAccounts;
}
public static int getNumAccounts()
{
return numAccounts;
}
}
and here is the driver:
//***********************************************************
// TestAccounts1
// A simple program to test the numAccts method of the
// Account class.
//***********************************************************
import java.util.Scanner;
public class TestAccounts1
{
public static void main(String[] args)
{
Account testAcct;
Scanner scan = new Scanner(System.in);
System.out.println("How many accounts would you like to create?");
int num = scan.nextInt();
for (int i=1; i<=num; i++)
{
testAcct = new Account(100, "Name", i);
System.out.println("\nCreated account " + testAcct);
System.out.println("Now there are " + Account.getNumAccounts() + " accounts");
}
}
}
My code compiles fine, but every time I try to compile my driver it gives me these same errors:
TestAccounts1.java:12: error: cannot find symbol
Account testAcct;
^
symbol: class Account
location: class TestAccounts1
TestAccounts1.java:21: error: cannot find symbol
testAcct = new Account(100, "Name", i);
^
symbol: class Account
location: class TestAccounts1
TestAccounts1.java:23: error: cannot find symbol
System.out.println("Now there are " + Account.getNumAccounts() + " accounts");
^
symbol: variable Account
location: class TestAccounts1
I really don't understand what's wrong.

New Topic/Question
Reply



MultiQuote




|