Skip to content

Commit ae47807

Browse files
committed
added to OneFishTwoFish
1 parent 7f33acc commit ae47807

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

  • src/main/java/org/teachingkidsprogramming/recipes/completed/section06modelviewcontroller

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//*************This Lesson is In Development*****************************//
1111
public class OneFishTwoFish
1212
{
13+
// Create a Scanner to make a string
1314
private static Scanner scanner;
1415
public static void main(String[] args)
1516
{
@@ -20,22 +21,32 @@ public static void main(String[] args)
2021
public static void makeAString()
2122
{
2223
final String input = "1 fish 2 fish red fish blue fish,black fish,blue fish,old fish,new fish ";
24+
// Use your scanner with your input
2325
scanner = new Scanner(input);
2426
System.err.println("\nWe have: " + input + '\n');
27+
// Now, tell a story with a new Scanner instance
2528
tellAStory(input);
2629
}
2730
private static void tellAStory(final String input)
2831
{
32+
// Use 'fish' as the base text w/your scanner [story]
2933
Scanner s = scanner.useDelimiter("\\s*fish\\s*");
34+
// Get the next number to use in your scanner [story]
3035
System.out.println("So: " + s.nextInt() + " and " + s.nextInt());
36+
// Get the next value to use in your scanner [story]
3137
System.out.println("And: " + s.next() + " and " + s.next() + '\n');
38+
// Iterate over each fish [string]
3239
for (String fish : new Iterable<String>()
3340
{
3441
@Override
42+
// Create a new string iterator
3543
public Iterator<String> iterator()
3644
{
45+
// Create a new scanner for your input
3746
scanner = new Scanner(input);
47+
// Use a comma to separate the strings in your story
3848
scanner.useDelimiter(",");
49+
// Return the result
3950
return scanner;
4051
}
4152
})
@@ -46,24 +57,36 @@ public Iterator<String> iterator()
4657
}
4758
public static void makeAFishyDecision(int numberOfFish)
4859
{
49-
String image = "//Users//lynnlangit//Documents//workspace//TeachingKidsProgramming.Source.Java//src//main//resources//icons//thumb-up.png";
50-
final ImageIcon icon = new ImageIcon(image);
60+
// Use a switch...case on the number of fish
5161
switch (numberOfFish)
5262
{
63+
// If number of fish is -1
5364
case -1 :
65+
String image = "//Users//lynnlangit//Documents//workspace//TeachingKidsProgramming.Source.Java//src//main//resources//icons//thumb-up.png";
66+
ImageIcon icon = new ImageIcon(image);
67+
// Show a message with the fancy message box this text, this title and this icon...
5468
FancyMessageBox.showMesage("Had a Fish", "Not hungry anymore...", icon);
69+
// End
5570
break;
5671
case 0 :
57-
FancyMessageBox.showMesage("No Fish", "None", icon);
72+
String image0 = "//Users//lynnlangit//Documents//workspace//TeachingKidsProgramming.Source.Java//src//main//resources//icons//information.png";
73+
ImageIcon icon0 = new ImageIcon(image0);
74+
FancyMessageBox.showMesage("No Fish", "Still hungry", icon0);
5875
break;
5976
case 1 :
60-
FancyMessageBox.showMesage("One Fish", "One", icon);
77+
String image1 = "//Users//lynnlangit//Documents//workspace//TeachingKidsProgramming.Source.Java//src//main//resources//icons//star.png";
78+
ImageIcon icon1 = new ImageIcon(image1);
79+
FancyMessageBox.showMesage("One Fish", "This one has a little star", icon1);
6180
break;
6281
case 2 :
63-
FancyMessageBox.showMesage("Two Fish", "Two", icon);
82+
String image2 = "//Users//lynnlangit//Documents//workspace//TeachingKidsProgramming.Source.Java//src//main//resources//icons//github.png";
83+
ImageIcon icon2 = new ImageIcon(image2);
84+
FancyMessageBox.showMesage("Two Fish", "Funny things are everywhere", icon2);
6485
break;
6586
default :
66-
FancyMessageBox.showMesage("Vegetaraian meal", "Fish are icky", icon);
87+
String image4 = "//Users//lynnlangit//Documents//workspace//TeachingKidsProgramming.Source.Java//src//main//resources//icons//hint.png";
88+
ImageIcon icon4 = new ImageIcon(image4);
89+
FancyMessageBox.showMesage("Vegetaraian meal", "Fish are icky", icon4);
6790
break;
6891
}
6992
}

0 commit comments

Comments
 (0)