Error Dialog Box

R

rock_steady111

What I need to do is add an error dialog box if the gallons of water
excedes 990,000 gallons when entered but I'm not sure how or where to
put it



String input;
int GallonsUsed;
double WaterUsage;
double SewerUsage;
double BaseService;
double Subtotal;
double Tax;
double TotalDue;
BaseService = 15.79;

input = JOptionPane.showInputDialog("Enter the number of
gallons used during the billing period.");



GallonsUsed = Integer.parseInt(input); //Changing the string
into an integer
WaterUsage = ((GallonsUsed / 100) * .27);
SewerUsage = ((GallonsUsed / 1000) * 1.49);
Subtotal = BaseService + WaterUsage + SewerUsage;
Tax = Subtotal * .06;
TotalDue = Subtotal + Tax;



//JOptionPane.showMessageDialog(null, "Base Price $15.79");
System.out.printf("Base Service $%.2f%n", BaseService);
System.out.printf("Water Usage $%.2f%n", WaterUsage);
System.out.printf("Sewer Usage $%.2f%n", SewerUsage);
System.out.printf("Sub Total $%.2f%n", Subtotal);
System.out.printf("Tax $%.2f%n", Tax);
System.out.printf("Total Due $%.2f%n", TotalDue);







}


}
 
P

Peter Duniho

What I need to do is add an error dialog box if the gallons of water
excedes 990,000 gallons when entered but I'm not sure how or where to
put it

Sounds like a question for your teacher.

From the code you posted, obviously you already have been exposed to the
JOptionPane class, which can be used for this purpose and others. If you
are having specific problems with respect to how to use it, post those
specific questions. The documentation provides the basic information
regarding "how".

If you need to know _where_ to use it, then that is dependent on the
design of your program, which is in turn dependent on the class assignment
you've been given. This is a question more appropriately directed at the
teacher. My guess is that you'd put it after you've received the input
that may be invalid, but before you use that input. That is, after all,
the usual nature of error reporting. In some cases, you may even want to
include a loop that doesn't exit until you've received correct input.

But only your teacher can tell you for sure what is correct in this
situation. He's the one who's provided the specification for the program.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top