Dornith
12-09-2011, 01:16 AM
Hello, and thank you in advance for your help.
I am new to Java. I am currently learning through a tutorial using Command-prompt. The tutorial is a little out of date, but not too much. I am trying to import one class file into another to extend it but it's not working.
It tells me I need a "." after "import Account" and I need a semicolon after that, but that doesn't make any sense and when I try it, it doesn't work.
If anyone can tell me the problem I will be very grateful.
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;}
}
InterestBearingAccount:
import Account;
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;
}
}
I am new to Java. I am currently learning through a tutorial using Command-prompt. The tutorial is a little out of date, but not too much. I am trying to import one class file into another to extend it but it's not working.
It tells me I need a "." after "import Account" and I need a semicolon after that, but that doesn't make any sense and when I try it, it doesn't work.
If anyone can tell me the problem I will be very grateful.
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;}
}
InterestBearingAccount:
import Account;
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;
}
}