• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

interface, exception help

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
below is my complete code for a bank account class and the measurable interface and my InsufficientFundsException class. My bankAccount class doesnt' recognize the interface or the exception class I designed. I keep getting the error below. The interface and the InsufficientFundsException class compiles with no problem.

C:\Documents and Settings\felipewalker\Desktop\BankAccount\BankAccount.java:5: cannot resolve symbol
symbol : class Measurable
location: class BankAccount
public class BankAccount implements Measurable{
^
C:\Documents and Settings\felipewalker\Desktop\BankAccount\BankAccount.java:49: cannot resolve symbol
symbol : class InsufficientFundsException
location: class BankAccount
throw new InsufficientFundsException("withdrawal of " + amount + " exceeds balance of " + balance);
^
2 errors

Tool completed with exit code 1

the Code
------------------
public interface Measurable {
double getMeasure();

}

public class InsufficientFundsException extends RuntimeException{
public InsufficientFundsException(){}

public InsufficientFundsException(String reason){
super(reason);
}
}



import javax.swing.JOptionPane;
/**
A bank account has a balance that can be changed by deposits and withdrawals.
*/
public class BankAccount implements Measurable{


/**
Constructs a bank account with a zero balance.
*/
public BankAccount(){
balance = 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance){
if(initialBalance >= 0){
balance = initialBalance;
}
else
JOptionPane.showMessageDialog(null,"Invalid Amount","Initial Balance can not be less than $0.00",JOptionPane.WARNING_MESSAGE);
}
/**
Deposits money into a bank account.
@param amount the amount to deposit
*/
public void deposit(double amount){
if (amount >= 0){
double newBalance = balance + amount;
balance = newBalance;
}
else
JOptionPane.showMessageDialog(null,"Invalid Amount","Deposit can not be less than $0.00",JOptionPane.WARNING_MESSAGE);

}
/**
Withdraws money from a bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount){
if (amount <= balance){
double newBalance = balance - amount;
balance = newBalance;
}
else {
balance = balance - OVERDRAFT_PENALTY;
throw new InsufficientFundsException("withdrawal of " + amount + " exceeds balance of " + balance);
}
}
/**
Gets the current balance of the bank account.
@return the curent balance
*/
public double getBalance(){
return balance;
}
/**
Adds intrest to the balance.
@param rate the current intrest rate
*/
public void transfer(BankAccount other, double amount){
withdraw(amount);
other.deposit(amount);
}

public double getMeasure(){
return balance;
}
private double balance;
final double OVERDRAFT_PENALTY = 35.00;
}

 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't say how you're compiling but, regardless, the problem is because your interface and Exception classes are not available on the classpath. All you probably need to do is add "." (the current directory) to the classpath. That way the compiler will be able to find the existing class files.

Jules
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly an answer to your question. Make sure your classpath is set up correctly and includes the directory where your .java files are stored.

Secondly a little tip on your bank account class. Don't use double or float to store decimal amounts. You can use this example to see what I mean
The expected answer here would be 0.9 but the answer obtained is 0.8999999999999999. What should you use instead ? BigDecimal would be my recommendation.
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually long or even int should be fine unless you're dealing with huge amounts or lots of decimal places (e.g. currency conversion). Just divide by 100 to display cents or whatever.

Jules
 
Felipe Walker
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help, that solved my issue
 
reply
    Bookmark Topic Watch Topic
  • New Topic