I'm on this debugging exercise that determines if an item number is invalid and if it is valid, then it would fall into two categories: Automotives or Housewares. Any item number over 999 is considered invalid, as well as any number below 111. The user is supposed to input an item number and to have one of the following three output: Automotive Department, Housewares Department, or invalid. The original exercise is as shown:
// DebugFive3.java
// Determines whether item number on order is valid
// Over 999 invalid
// Less than 111 Invalid
// Valid and less than 500 - Automotive Department
// Valid and 500 or higher Housewares Department
import javax.swing.*;
public class DebugFive3
{
public static void main (String args[])
{
int item;
String itemString, output;
itemSting = JOptionPane.showInputDialog(null,
"Please enter item number
item = Integer.parseInt(itemString);
if(item < 111)
output = "Item number too low";
else
output = "Item number too high";
else
if(item < 500)
output = "Valid - in Automotive Department";
else
output = "Valid - Item in Housewares Department";
JOptionPane.showMessageDialog(output);
System.exit(0);
}
}
The first thing I did was to combine the two if out out statements so that if a number was invalid, then only one statement would be needed to evaluate that. My fixed version so far is this:
// Alphonsus Delgra
// October 27, 2010
// Lab 5-1
// DebugFive3.java
// Determines whether item number on order is valid
// Over 999 invalid
// Less than 111 Invalid
// Valid and less than 500 - Automotive Department
// Valid and 500 or higher Housewares Department
import javax.swing.*;
public class FixDebugFive3
{
public static void main (String args[])
{
int item;
String itemString, output;
itemString = JOptionPane.showInputDialog(null,
"Please enter item number: ");
item = Integer.parseInt(itemString);
if(item < 111 || item > 999)
output = "Invalid item number (too low or too high";
else
if(item < 500)
output = "Valid - in Automotive Department";
else
output = "Valid - Item in Housewares Department";
JOptionPane.showMessageDialog(output);
System.exit(0);
}
}
The only problem I had when compiling was this:
----jGRASP exec: javac -g H:\Java 2nd\FixDebugFive3.java
FixDebugFive3.java:27: cannot find symbol
symbol : method showMessageDialog(java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog(output);
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Without a symbol I don't know what's wrong with that. I checked towards the beginning if I used the correct import with javax.swing.* but that imports all Java packages. Checking through spelling errors other details it looked fine to me. Thanks again for you time.

New Topic/Question
Reply



MultiQuote



|