2 Replies - 289 Views - Last Post: 29 November 2012 - 08:00 AM Rate Topic: -----

#1 lamapost0001  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 12

Driver errors.

Posted 28 November 2012 - 06:23 PM

Here is my completed code:

//*******************************************************
// 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.

Is This A Good Question/Topic? 0
  • +

Replies To: Driver errors.

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Driver errors.

Posted 28 November 2012 - 07:36 PM

What is the name of your two .java files and are they in the same directory ?
Was This Post Helpful? 1
  • +
  • -

#3 lamapost0001  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-November 12

Re: Driver errors.

Posted 29 November 2012 - 08:00 AM

View Postpbl, on 28 November 2012 - 07:36 PM, said:

What is the name of your two .java files and are they in the same directory ?


Wow, thank you. That was the problem the whole time. I thought I had them both saved to my desktop, but that was no the case!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1