Again, I am a java n00b and I am trying to learn from scratch and running into some embarrassing problems.
I got an Account class as follows:Account.java
public class Account
{
protected double balance;
// Constructor to initialize balance
public Account( double amount )
{
balance = amount;
}
// Overloaded constructor for empty balance
public Account()
{
balance = 0.0;
}
public void deposit( double amount )
{
balance += amount;
}
public double withdraw( double amount )
{
// See if amount can be withdrawn
if (balance >= amount)
{
balance -= amount;
return amount;
}
else
// Withdrawal not allowed
return 0.0;
}
public double getbalance()
{
return balance;
}
}
I am trying to use extends to inherit the methods and variables in this class. So, I used InterestBearingAccount.java
import Account;
class InterestBearingAccount extends Account
{
// Default interest rate of 7.95 percent (const)
private static double default_interest = 7.95;
// Current interest rate
private double interest_rate;
// Overloaded constructor accepting balance and an interest rate
public InterestBearingAccount( double amount, double interest)
{
balance = amount;
interest_rate = interest;
}
// Overloaded constructor accepting balance with a default interest rate
public InterestBearingAccount( double amount )
{
balance = amount;
interest_rate = default_interest;
}
// Overloaded constructor with empty balance and a default interest rate
public InterestBearingAccount()
{
balance = 0.0;
interest_rate = default_interest;
}
public void add_monthly_interest()
{
// Add interest to our account
balance = balance +
(balance * interest_rate / 100) / 12;
}
}
I get an error saying import error ‘.’ expected when I try to compile. All the files are in the same folder.
I did javac -cp . InterestBearingAccount
If all the files are in the same folder / package, you don’t need to do an import.