Results 1 to 2 of 2
Thread: Multiple Exceptions with Array
- 12-11-2009, 06:56 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 11
- Rep Power
- 0
Multiple Exceptions with Array
Good Afternoon,
I would like to learn, and need direction if possible please.
Here is my challenge.
I want to pull from an Array of multiple "error messages" when the user inputs the incorrect data.
This is my array:
Then I would create a class that displays one of the messages(easy enough I think ).Java Code:import java.util.*; public class OrderMessages { public static void main(String[] args) { String[] errorMessages = new String[7]; errorMessages[0] = "The Item is not numeric"; errorMessages[1] = "The quantity is not numeric"; errorMessages[2] = "The item number is too low"; errorMessages[3] = "The item number is to high"; errorMessages[4] = "The quantity ordered is too low"; errorMessages[5] = "The quantity ordered is too high"; errorMessages[6] = "The item number is not valid"; { System.out.println(errorMessages[0]); } } }
Then an Applet.
The user then inputs an item number (ie 1) then a quantity.
I then assign a price to it (i.e $0.89ea)., and caluculate the math..etc...
If he/she inputs the incorrect info as per my exception array, then the error is displayed.
I'm assuming the try and catch with multiple catches.
all wrapped in an Applet.
Trying to find the correct "starting point" has been my challenge.
I've tries a couple different approaches on paper so far, but they all seem to go nowhere.
Now, I'm more confused than ever.
yes, I am a mature student, and I am learning for fun.
if I am not using proper terms etc...please let me know..
Thank you in advance
Cutter
- 12-11-2009, 07:02 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Don't use arrays for that purpose although you think they look neat and organised for the purpose; arrays are so Fortranesque; use exceptions instead: throw an exception that contains the appropriate message right where you detect the error. An IllegalArgumentException would do fine.
kind regards,
Jos
Similar Threads
-
Exceptions
By hedonist in forum New To JavaReplies: 10Last Post: 09-08-2009, 08:38 AM -
Exceptions in thread
By Goodwater in forum New To JavaReplies: 4Last Post: 03-16-2009, 03:00 AM -
Need Help With Exceptions
By maggie_2 in forum New To JavaReplies: 5Last Post: 12-15-2008, 07:12 PM -
Can I store multiple objects in an array
By lareauk in forum New To JavaReplies: 9Last Post: 05-29-2008, 03:57 AM -
Question on Exceptions
By yelllow4u in forum New To JavaReplies: 6Last Post: 07-27-2007, 01:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks