Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Class is public, should be declared in a file?

807598Aug 28 2006 — edited Apr 6 2007
So 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) ;
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 4 2007
Added on Aug 28 2006
18 comments
7,012 views