...

View Full Version : Java Packages/"Cannot find Symbol"



Dornith
12-11-2011, 09:54 PM
Hello. I am new to Java and am learning off some tutorials online but for one lesson, the code it gave me didn't work. The lessons are a little out of date so I think that might be the problem. Right now I am working with packages, importing, and extending. Here is my code:

CreateAccount.class


import account.*;

class CreateAccount
{
public static void main(String args[])
{
Account MyAccount = new Account(40.00);
System.out.println("Your account has $" + MyAccount.GetBalance());
MyAccount.Deposit(30.00);
System.out.println("Your account has $" + MyAccount.GetBalance() + " after a depoist of $30");
MyAccount.Withdraw(60.00);
System.out.println("Your account has $" + MyAccount.GetBalance() + " after a withdraw of $60");
MyAccount.AddInterest();
System.out.println("Your account has $" + MyAccount.GetBalance() + " after interest");
}
}


InterestBearingAccount.class


package JavaTest;

import account.*;

public class InterestBearingAccount extends Account
{
private static double DInterest = 7.95;

private double InterestRate;

public InterestBearingAccount(double Amount, double Interest)
{
balance = Amount;
InterestRate = Interest;
}

public InterestBearingAccount(double Amount)
{
balance = Amount;
InterestRate = DInterest;
}

public InterestBearingAccount()
{
balance = 0.0;
InterestRate = DInterest;
}

public void AddInterest()
{
balance += (balance*InterestRate/100)/12;
}
}


account/Account.class


package account;

public class Account
{
protected double balance;

public Account(double amount)
{balance = amount;}

public Account()
{balance = 0.0;}

public void Deposit(double amount)
{balance += amount;}

public double Withdraw(double amount)
{
if (balance >= amount)
{
balance -= amount;
return amount;
}
else
return 0.0;
}

public double GetBalance()
{return balance;}
}


When I try to compile CreateInterestAccount it gives me an error on the first "InterestBearingAccount" in, "InterestBearingAccount MyAccount = new InterestBearingAccount();" The error says, "Cannot find symbol."

Thanks for the help!

Fou-Lu
12-12-2011, 04:26 AM
InterestBearingAccount is a part of package JavaTest. You need to import in JavaTest.InterestingBearingAccount.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum