Skip to content

Commit 12ab190

Browse files
committed
updated variation ExceptionalAdLibs w/@samanthalangit
1 parent 4011aab commit 12ab190

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@ public static void main(String[] args)
1010
if (adverb.isEmpty())
1111
{
1212
MessageBox.showMessage("L Y don't you want to play? To start you need one adverb.");
13-
return;
13+
adverb = askAdverbAgain();
1414
}
15-
else if (adverb.matches("[\\d]*"))
15+
if (adverb.matches("[\\d]*"))
1616
{
1717
MessageBox.showMessage("Numbers are NOT adverbs, try again");
18-
return;
18+
adverb = askAdverbAgain();
1919
}
2020
String currentAdverb = adverb;
2121
String edverb = MessageBox.askForTextInput("What is the -ed verb?");
2222
if (edverb.isEmpty())
2323
{
2424
MessageBox.showMessage("Don't like verbs? You need one now.");
25-
return;
25+
edverb = askEdVerbAgain();
2626
}
27-
else if (edverb.matches("[\\d]*"))
27+
if (edverb.matches("[\\d]*"))
2828
{
2929
MessageBox.showMessage("Numbers are != verbs, try again");
30-
return;
30+
edverb = askEdVerbAgain();
3131
}
3232
String currentEdVerb = edverb;
3333
String bodyPart = MessageBox.askForTextInput("What is the body part?");
3434
if (bodyPart.isEmpty())
3535
{
3636
MessageBox.showMessage("No body, no story, pay attention and start over");
37-
return;
37+
bodyPart = askBodyPartAgain();
3838
}
39-
else if (bodyPart.matches("[\\d]*"))
39+
if (bodyPart.matches("[\\d]*"))
4040
{
4141
MessageBox.showMessage("Numbers <> body parts, try again");
42-
return;
42+
bodyPart = askBodyPartAgain();
4343
}
4444
String currentBodyPart = bodyPart;
4545
String currentStory = "Today ";
@@ -48,4 +48,25 @@ else if (bodyPart.matches("[\\d]*"))
4848
currentStory = currentStory + "my " + currentBodyPart + ". ";
4949
MessageBox.showMessage(currentStory);
5050
}
51+
52+
private static String askBodyPartAgain()
53+
{
54+
String bodyPart;
55+
bodyPart = MessageBox.askForTextInput("What is the body part?");
56+
return bodyPart;
57+
}
58+
59+
private static String askEdVerbAgain()
60+
{
61+
String edverb;
62+
edverb = MessageBox.askForTextInput("What is the -ed verb?");
63+
return edverb;
64+
}
65+
66+
private static String askAdverbAgain()
67+
{
68+
String adverb;
69+
adverb = MessageBox.askForTextInput("What is the adverb?");
70+
return adverb;
71+
}
5172
}

0 commit comments

Comments
 (0)