Skip to content

Commit d84385b

Browse files
committed
working on ExceptionalAdLIbs w/ @samanthalangit
1 parent 7dacd66 commit d84385b

2 files changed

Lines changed: 77 additions & 64 deletions

File tree

src/main/java/org/teachingextensions/windows/MessageBox.java

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,64 @@
1616
* Use it to collect numerical input from the user<br>
1717
* Or to display a message for the user to read.<br>
1818
*/
19-
public class MessageBox {
20-
private static MessageBoxInstance messageBox = new MessageBoxInstance();
21-
22-
/**
23-
* Prints a request for a numerical input to the window. <br>
24-
* <b>Example:</b>
25-
* {@code int cookies = MessageBox.askForNumericalInput("How many cookies would you like?");}
26-
*
27-
* @param message
28-
* the text to be displayed
29-
* @return the user input
30-
*/
31-
public static int askForNumericalInput(String message) {
32-
return messageBox.askForNumericalInput(message);
33-
}
34-
35-
/**
36-
* Prints a request for a text input to the window. <br>
37-
* <b>Example:</b>
38-
* {@code String name = MessageBox.askForTextInput("What is your nickname?");}
39-
*
40-
* @param message
41-
* the text to be displayed
42-
* @return the user input
43-
*/
44-
public static String askForTextInput(String message) {
45-
return messageBox.askForTextInput(message);
46-
}
47-
48-
/**
49-
* Prints the message to the window. <br>
50-
* <b>Example:</b> {@code MessageBox.showMessage(&quot;Girl programmers rule!&quot;);}
51-
*
52-
* @param message
53-
* the text to be displayed
54-
*/
55-
public static void showMessage(String message) {
56-
messageBox.showMessage(message);
57-
}
58-
59-
public static void mock(MessageBoxInstance messageBoxMock) {
60-
messageBox = messageBoxMock;
61-
}
62-
63-
public static class MessageBoxInstance {
64-
public int askForNumericalInput(String message) {
65-
String input = askForTextInput(message);
66-
return NumberUtils.load(input, 0);
67-
}
68-
69-
public String askForTextInput(String message) {
70-
return JOptionPane.showInputDialog(message);
71-
}
72-
73-
public void showMessage(String message) {
74-
JOptionPane.showMessageDialog(null, message);
75-
}
76-
}
19+
public class MessageBox
20+
{
21+
private static MessageBoxInstance messageBox = new MessageBoxInstance();
22+
/**
23+
* Prints a request for a numerical input to the window. <br>
24+
* <b>Example:</b>
25+
* {@code int cookies = MessageBox.askForNumericalInput("How many cookies would you like?");}
26+
*
27+
* @param message
28+
* the text to be displayed
29+
* @return the user input
30+
*/
31+
public static int askForNumericalInput(String message)
32+
{
33+
return messageBox.askForNumericalInput(message);
34+
}
35+
/**
36+
* Prints a request for a text input to the window. <br>
37+
* <b>Example:</b>
38+
* {@code String name = MessageBox.askForTextInput("What is your nickname?");}
39+
*
40+
* @param message
41+
* the text to be displayed
42+
* @return the user input
43+
*/
44+
public static String askForTextInput(String message)
45+
{
46+
return messageBox.askForTextInput(message);
47+
}
48+
/**
49+
* Prints the message to the window. <br>
50+
* <b>Example:</b> {@code MessageBox.showMessage("Girl programmers rule!");}
51+
*
52+
* @param message
53+
* the text to be displayed
54+
*/
55+
public static void showMessage(String message)
56+
{
57+
messageBox.showMessage(message);
58+
}
59+
public static void mock(MessageBoxInstance messageBoxMock)
60+
{
61+
messageBox = messageBoxMock;
62+
}
63+
public static class MessageBoxInstance
64+
{
65+
public int askForNumericalInput(String message)
66+
{
67+
String input = askForTextInput(message);
68+
return NumberUtils.load(input, 0);
69+
}
70+
public String askForTextInput(String message)
71+
{
72+
return JOptionPane.showInputDialog(message);
73+
}
74+
public void showMessage(String message)
75+
{
76+
JOptionPane.showMessageDialog(null, message);
77+
}
78+
}
7779
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section06modelviewcontroller/ExceptionalAdLibs.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public static void main(String[] args)
1111
String adverb = MessageBox.askForTextInput("What is the adverb?");
1212
if (adverb.isEmpty())
1313
{
14-
MessageBox.showMessage("Required value, pay attention and start over");
14+
MessageBox.showMessage("L Y don't you want to play? To start you need one adverb.");
1515
return;
1616
}
17-
else if (adverb.matches("[\\d]"))
17+
else if (adverb.matches("[\\d]*"))
1818
{
1919
MessageBox.showMessage("Numbers are NOT adverbs, try again");
2020
return;
@@ -24,17 +24,28 @@ else if (adverb.matches("[\\d]"))
2424
String edverb = MessageBox.askForTextInput("What is the -ed verb?");
2525
if (edverb.isEmpty())
2626
{
27-
MessageBox.showMessage("Don't like verbs? Sorry you need one now, pay attention and start over");
27+
MessageBox.showMessage("Don't like verbs? You need one now.");
2828
return;
2929
}
30-
else if (edverb.matches("[\\d]"))
30+
else if (edverb.matches("[\\d]*"))
3131
{
32-
MessageBox.showMessage("Numbers are NOT verbs, try again");
32+
MessageBox.showMessage("Numbers are != verbs, try again");
3333
return;
3434
}
3535
String currentEdVerb = edverb;
3636
//Ask the user to enter a body part, save it as currentBodyPart --#6
37-
String currentBodyPart = MessageBox.askForTextInput("What is the body part?");
37+
String bodyPart = MessageBox.askForTextInput("What is the body part?");
38+
if (bodyPart.isEmpty())
39+
{
40+
MessageBox.showMessage("No body, no story, pay attention and start over");
41+
return;
42+
}
43+
else if (bodyPart.matches("[\\d]*"))
44+
{
45+
MessageBox.showMessage("Numbers <> body parts, try again");
46+
return;
47+
}
48+
String currentBodyPart = bodyPart;
3849
//Set the value of the currentStory to the word "Today " --#1.2
3950
String currentStory = "Today ";
4051
//Add the words "I woke " + currentAdverb + ". " to the currentStory --#3

0 commit comments

Comments
 (0)