-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebugEight1.java
More file actions
37 lines (37 loc) · 1.05 KB
/
DebugEight1.java
File metadata and controls
37 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Application prompts user showing valid shipping codes
// accepts a shipping code
// and determines if it is valid
import javax.swing.*;
public class DebugEight1
{
public static void main(String args[])
{
char userCode;
String entry, message;
boolean found = false;
char[] okayCodes = {'A''C''T''H'};
StringBuffer prompt = new
StringBuffer("Enter shipping code for this delivery\nValid codes are: ");
for(int x = 0; x <= okayCodes.length; ++x)
{
prompt.append(okayCodes[x]);
if(x == (okayCodes.length - 1))
prompt.append(", ");
}
entry = JOptionPane.showInputDialog(null,
prompt);
userCode = entry.charAt();
for(int i = 0; x < okayCodes.length; ++i)
{
if(userCode == okayCodes[i])
{
found = true;
}
}
if(found)
message = "Good code";
else
message = "Sorry code not found;
JOptionPane.showMessageDialog(null, message);
}
}