Class is public, should be declared in a file?
807598Aug 28 2006 — edited Apr 6 2007So I'm running a program called BankAccount.java. When I tried to comile it (javac BankAccount.java) I get a message that says
BankAccount.java:4:class InsufficientFundsException is public, should be declared in a file named InsufficientFundsException.java
public class InsufficientFundsException extends Exception
^
1 error
In case you need to see it, my code is
import java.util.*;
import java.text.*;
public class InsufficientFundsException extends Exception
{
private int accountNumber;
private int withdrawAmount;
private int balanceAmount;
private Date date;
private DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
private NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
public InsufficientFundsException(int actNumb,
int amount,
int balance)
{
date = new Date();
accountNumber = actNumb;
withdrawAmount = amount;
balanceAmount = balance;
}
public String toString()
{
return getClass().getName() + " on " + df.format(date)
+ ". Withdraw of " + nf.format(withdrawAmount)
+ " rejected. Balance of account #" + accountNumber
+ " remains at " + nf.format(balanceAmount) ;
}
}