Simple class problem

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
kev

Simple class problem

Post by kev »

I am having trouple with this simple class:

/** test
* @KPB
*/

public class testofclass
{
static final double RATE = 0.05;
static double purchase;

public static void main(String[] args)
{
double tax;
double total;
purchase=Double.parseDouble(args[0]);
tax = RATE * purchase;
total = purchase + tax;
System.out.println("Total: " + total);
}
}


****
When I compile(which works fine) and run this application, I get this error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at testofclass.main(testofclass.java:14)


Can anyone provide a quick fix?
emann

Re: Simple class problem

Post by emann »

args[0] = your program name

try
purchase=Double.parseDouble(args[1]);
Henrik S. Larsen

Re: Simple class problem

Post by Henrik S. Larsen »

Not in java :-)

args[0] is the first argument / parameter to the class.
Seems to me, that you are running the class without any arguments
Ted Herman

Re: Simple class problem

Post by Ted Herman »

Yes, I don't think you can define static constants in a class with the main method...
Post Reply