Skip to content

Commit d5984a1

Browse files
committed
added stubs for HiLow kata questions
1 parent 5b450cf commit d5984a1

File tree

7 files changed

+272
-10
lines changed

7 files changed

+272
-10
lines changed

src/main/java/org/teachingkidsprogramming/recipes/completed/section03ifs/HiLowVariation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public class HiLowVariation
1010
public static void main(String[] args)
1111
{
1212
int answer = NumberUtils.getRandomInt(1, 100);
13-
//TIP: for testing you may want to use a static answer
14-
//int answer = 12;
13+
// TIP: for testing you may want to use a static answer
14+
// int answer = 12;
1515
for (int i = 0; i < 8; i++)
1616
{
1717
int guess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
18-
if (guess < 1)
18+
if (guess <= 0)
1919
{
20-
MessageBox.showMessage("Please guess a positive number!");
20+
MessageBox.showMessage("No Zero or Negative numbers allowed - you lose!");
2121
System.exit(0);
2222
}
2323
if (guess > 100)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
2+
3+
import java.awt.Toolkit;
4+
5+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
6+
7+
//------------Kata Question---------------//
8+
// What happens when you enter a decimal and why?
9+
// What should happen?
10+
// Can you fix the bug?
11+
// Write out the steps in English
12+
// Then translate the steps into code
13+
// Make sure to run after each line
14+
//
15+
public class HiLowFixBugSolution_5b
16+
{
17+
public static void main(String[] args)
18+
{
19+
// int answer = NumberUtils.getRandomInt(1, 100);
20+
int answer = 12;
21+
for (int i = 0; i < 8; i++)
22+
{
23+
double originalGuess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
24+
int guess = (int) originalGuess;
25+
if (guess == 0)
26+
{
27+
MessageBox.showMessage("No Zero allowed, you lose!");
28+
System.exit(0);
29+
}
30+
if (guess > 100)
31+
{
32+
MessageBox.showMessage("Number too big, you lose!");
33+
System.exit(0);
34+
}
35+
if (guess == answer)
36+
{
37+
Toolkit.getDefaultToolkit().beep();
38+
MessageBox.showMessage("You won!");
39+
System.exit(0);
40+
}
41+
else if (guess < 1)
42+
{
43+
MessageBox.showMessage("Please guess a positive number only!");
44+
}
45+
else if (guess > answer)
46+
{
47+
MessageBox.showMessage("Try a lower number.");
48+
}
49+
else if (guess < answer)
50+
{
51+
MessageBox.showMessage("Try a higher number.");
52+
}
53+
}
54+
MessageBox.showMessage("You lost!");
55+
}
56+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
2+
3+
import java.awt.Toolkit;
4+
5+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
6+
7+
//------------Kata Question---------------//
8+
// What happens when you enter a decimal and why?
9+
// What should happen?
10+
// Can you fix the bug?
11+
// Write out the steps in English
12+
// Then translate the steps into code
13+
// Make sure to run after each line
14+
//
15+
public class HiLowFixBug_04
16+
{
17+
public static void main(String[] args)
18+
{
19+
// int answer = NumberUtils.getRandomInt(1, 100);
20+
int answer = 12;
21+
for (int i = 0; i < 8; i++)
22+
{
23+
int guess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
24+
if (guess == 0)
25+
{
26+
MessageBox.showMessage("No Zero allowed, you lose!");
27+
System.exit(0);
28+
}
29+
if (guess > 100)
30+
{
31+
MessageBox.showMessage("Number too big, you lose!");
32+
System.exit(0);
33+
}
34+
if (guess == answer)
35+
{
36+
Toolkit.getDefaultToolkit().beep();
37+
MessageBox.showMessage("You won!");
38+
System.exit(0);
39+
}
40+
else if (guess < 1)
41+
{
42+
MessageBox.showMessage("Please guess a positive number only!");
43+
}
44+
else if (guess > answer)
45+
{
46+
MessageBox.showMessage("Try a lower number.");
47+
}
48+
else if (guess < answer)
49+
{
50+
MessageBox.showMessage("Try a higher number.");
51+
}
52+
}
53+
MessageBox.showMessage("You lost!");
54+
}
55+
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section03ifs/HiLowKataQuestion.java renamed to src/main/java/org/teachingkidsprogramming/recipes/completed/section03ifs/KataQuestions/HiLowNoZero_01.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
package org.teachingkidsprogramming.recipes.completed.section03ifs;
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
22

33
import java.awt.Toolkit;
44

55
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
66

7-
//
87
//------------Kata Question---------------//
9-
// How would you make sure the guess is a positive number?
8+
// How would you make sure the guess is NOT zero
9+
// and end the game if the guess is zero?
1010
// Write out the steps in English
1111
// Then translate the steps into code
1212
// Make sure to run after each line
1313
//
14-
public class HiLowKataQuestion
14+
public class HiLowNoZero_01
1515
{
1616
public static void main(String[] args)
1717
{
18-
// Choose a random number between 1 and 100 --#4.1 (fake!) & --#13 ***Math does not permit the generation of a random number between an interval
19-
//int answer = NumberUtils.getRandomInt(1, 100);
18+
// int answer = NumberUtils.getRandomInt(1, 100);
2019
int answer = 12;
2120
for (int i = 0; i < 8; i++)
2221
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
2+
3+
import java.awt.Toolkit;
4+
5+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
6+
7+
//------------Kata Question---------------//
8+
// How would you make sure the guess is NOT zero
9+
// and end the game if the guess is zero?
10+
// How would you make sure the guess is NOT a negative number
11+
// but go to the next turn if the guess is negative?
12+
// Write out the steps in English
13+
// Then translate the steps into code
14+
// Make sure to run after each line
15+
//
16+
public class HiLowToNoZeroNoNegativeAndKeepPlaying_02
17+
{
18+
public static void main(String[] args)
19+
{
20+
// int answer = NumberUtils.getRandomInt(1, 100);
21+
int answer = 12;
22+
for (int i = 0; i < 8; i++)
23+
{
24+
int guess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
25+
if (guess == 0)
26+
{
27+
MessageBox.showMessage("No Zero allowed, you lose!");
28+
System.exit(0);
29+
}
30+
if (guess == answer)
31+
{
32+
Toolkit.getDefaultToolkit().beep();
33+
MessageBox.showMessage("You won!");
34+
System.exit(0);
35+
}
36+
else if (guess > answer)
37+
{
38+
MessageBox.showMessage("Try a lower number.");
39+
}
40+
else if (guess < answer)
41+
{
42+
MessageBox.showMessage("Try a higher number.");
43+
}
44+
}
45+
MessageBox.showMessage("You lost!");
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
2+
3+
import java.awt.Toolkit;
4+
5+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
6+
7+
//------------Kata Question---------------//
8+
// How would you make sure the guess is NOT zero
9+
// and end the game if the guess is zero?
10+
// How would you make sure the guess is NOT a negative number
11+
// but go to the next turn if the guess is negative?
12+
// How would you make sure the guess is less than 100
13+
// and end the game if the guess is greater than 100?
14+
// Write out the steps in English
15+
// Then translate the steps into code
16+
// Make sure to run after each line
17+
//
18+
public class HiLowToNoZeroNoNegativePlayOnAndAddUpperBound_03
19+
{
20+
public static void main(String[] args)
21+
{
22+
// int answer = NumberUtils.getRandomInt(1, 100);
23+
int answer = 12;
24+
for (int i = 0; i < 8; i++)
25+
{
26+
int guess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
27+
if (guess == 0)
28+
{
29+
MessageBox.showMessage("No Zero allowed, you lose!");
30+
System.exit(0);
31+
}
32+
if (guess == answer)
33+
{
34+
Toolkit.getDefaultToolkit().beep();
35+
MessageBox.showMessage("You won!");
36+
System.exit(0);
37+
}
38+
else if (guess < 1)
39+
{
40+
MessageBox.showMessage("Please guess a positive number only!");
41+
}
42+
else if (guess > answer)
43+
{
44+
MessageBox.showMessage("Try a lower number.");
45+
}
46+
else if (guess < answer)
47+
{
48+
MessageBox.showMessage("Try a higher number.");
49+
}
50+
}
51+
MessageBox.showMessage("You lost!");
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
2+
3+
import java.awt.Toolkit;
4+
5+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
6+
7+
//------------Kata Question---------------//
8+
// How would you make sure the guess is a positive number
9+
// and that the guess is less than 100
10+
// and is a whole number only
11+
// and not letters?
12+
// Write out the steps in English
13+
// Then translate the steps into code
14+
// Make sure to run after each line
15+
//
16+
public class HiLowToPosBoundWholeAndNotLettersGuess_05
17+
{
18+
public static void main(String[] args)
19+
{
20+
// double answer = NumberUtils.getRandomInt(1, 100);
21+
int answer = 12;
22+
for (int i = 0; i < 8; i++)
23+
{
24+
int guess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
25+
if (guess < 1)
26+
{
27+
MessageBox.showMessage("Please guess a positive number!");
28+
System.exit(0);
29+
}
30+
if (guess > 100)
31+
{
32+
MessageBox.showMessage("Please guess a number less than 100!");
33+
System.exit(0);
34+
}
35+
if (guess == answer)
36+
{
37+
Toolkit.getDefaultToolkit().beep();
38+
MessageBox.showMessage("You won!");
39+
System.exit(0);
40+
}
41+
else if (guess > answer)
42+
{
43+
MessageBox.showMessage("Try a lower number.");
44+
}
45+
else if (guess < answer)
46+
{
47+
MessageBox.showMessage("Try a higher number.");
48+
}
49+
}
50+
MessageBox.showMessage("You lost!");
51+
}
52+
}

0 commit comments

Comments
 (0)