Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Java Packages/"Cannot find Symbol"

    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
    Code:
    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
    Code:
    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
    Code:
    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!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    InterestBearingAccount is a part of package JavaTest. You need to import in JavaTest.InterestingBearingAccount.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •