Results 1 to 6 of 6
- 02-26-2009, 09:20 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 4
- Rep Power
- 0
Error message pops up no matter what?
public void deliveryCharge()
{
// VARIABLE DECLARATIONS/DEFINITIONS (IPO) ********************************************
// *** INPUT VARIABLES ***
DecimalFormat dollarDecimalPlaces = new DecimalFormat("$#,##0.00");//This is the dollar decimal format that gives the dollar amounts a dollar sign the correct decimal format.
String userName; //The user's name
String pickupOption; //Find out if the user is picking up
String packageWeightInfo;//String regarding to weight of package in pounds
double packageWeight = 0;//Weight of the package in pounds
double pickupCharge = 0;//Charge if user picks up package
char Y;
char X;
// *** PROCESSING VARIABLES ***
// (These may be constants intermediate or temporary storage variables.)
double cost = 0; //Cost per pound
// *** OUTPUT VARIABLES ***
double deliveryCharge;//This is the result of the program
// THE CODING STATEMENTS/ACTIONS (IIPO) ***********************************************
// INITIALIZATION
JOptionPane.showMessageDialog(null, "Welcome to the Dawg Delivery Service!");//Displays a welcoming message to the user
// INPUTS - COLLECT INPUT FROM THE USER OR ANOTHER SOURCE - AND VALIDATE THE INPUTS.
//Get the User's name:
userName = JOptionPane.showInputDialog("Please enter your full name.");//Asks the user to enter their name
if (userName.length() == 0)
{
JOptionPane.showMessageDialog(null, "ERROR! You cannot have a length of zero!"); //If nothing is entered in the userName input box, then this will pop up.
System.exit(0);
}
pickupOption = JOptionPane.showInputDialog("Is this package being picked up? Please enter Y or N:");//Asks user to enter if the package is being picked up. Only Y or N will be acceptable for answers.
if (pickupOption.substring(0,1).equals("Y") || pickupOption.substring(0,1).equals("y"))
{
pickupCharge = 2; //Gives correct pick up charge if item is picked up
}
if (pickupOption.substring(0,1).equals("N") || pickupOption.substring(0,1).equals("n"))
{
pickupCharge = 0; //Gives zero pick up charge if item is not picked up
}
if (pickupOption.substring(0,1) != ("N") || pickupOption.substring(0,1) != ("n"))
{
JOptionPane.showMessageDialog(null, "ERROR! You must enter Y or N!"); //If something other than Y or N is entered, then this will pop up.
System.exit(0);
}
if (pickupOption.substring(0,1) != ("Y") || pickupOption.substring(0,1) != ("y"))
{
JOptionPane.showMessageDialog(null, "ERROR! You must enter Y or N!"); //If something other than Y or N is entered, then this will pop up.
System.exit(0);
}
When my program is running, no matter what I type in for the pickupOption, it gives me my error message. WHY???
-
It's very hard to read your code as it has not retained its formatting.
Please use code tags so that your code will be well-formatted and readable. To do this, either highlight your code block and press the "code" button at the top above the message block or place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:
Good luckJava Code:[code] // your code block goes here // notice that the top and bottom tags are different here [/code]
-
Also, what is the error message? And what line of code causes it?
also, don't use == or != for String. Use either the equals method or equalsIgnoreCase method.Last edited by Fubarable; 02-26-2009 at 09:34 PM.
- 02-26-2009, 09:39 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 4
- Rep Power
- 0
I'm not really sure how to use this site completely yet. The message I get is the JOptionPane I created that says "ERROR! You must enter Y or N!"
I have to somehow get that to only pop up when the user enters something other than Y, y, N, or n. I do not know how to go about doing that so that's why I did the
if (pickupOption.substring(0,1) != ("N") || pickupOption.substring(0,1) != ("n"))
{
JOptionPane.showMessageDialog(null, "ERROR! You must enter Y or N!"); //If something other than Y or N is entered, then this will pop up.
System.exit(0);
}
Is there a better or more correct way to make this only pop up when something other than those chars are entered? Thanks!
-
Again:
1) use code tags when posting code. Shoot, I showed you how to do this, so it shouldn't be hard.
2) Again, don't use == or != when comparing Strings.
3) Figuring out how to get your logic to work will take some sitting and thinking without your computer. Work on paper to figure out the correct logic -- it's not hard with just a little effort. One way is to check for all the correct letters using a single if statement, another is to use a few if then else if statements,... but again, it's far better if you are the one who figures this out. You can do it.
- 02-26-2009, 10:10 PM #6
Member
- Join Date
- Feb 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Error Message in JBuilder
By RavenNevarmore in forum New To JavaReplies: 4Last Post: 10-08-2008, 06:53 AM -
strange Error message
By little_polarbear in forum New To JavaReplies: 4Last Post: 08-25-2008, 11:45 PM -
Can't solve error message while looping
By BHCluster in forum New To JavaReplies: 15Last Post: 04-22-2008, 10:51 AM -
java error message
By baileyr in forum New To JavaReplies: 2Last Post: 01-23-2008, 03:47 AM -
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 02:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks