Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.teachingkidsprogramming.recipes;

import org.teachingextensions.logo.Tortoise;

public class FourSquare
{
public static void main(String[] args)
{
// Show the tortoise --#1
Tortoise.
// Make the tortoise move as fast as possible --#8
// Do the following 4 times --#9
// drawSquare (recipe below) --#7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
package org.teachingkidsprogramming.recipes;

import java.util.Random;

import org.teachingextensions.logo.utils.Sounds;
import org.teachingextensions.windows.MessageBox;

public class HiLow
{
public static void main(String[] args)
{
// Choose a random number between 1 and 100 --#4.1 (fake!) & --#13
// Do the following 8 times --#9
// Ask the user for a guess --#1
// If the guess is correct --#4
// Play a bell --#2
// Tell the user that they won the game --#3
// and exit --#10
// Otherwise, if the guess is too high --#6
// Tell the end user that it is too high --#5
// Otherwise, if the guess is too low --#8
// Tell the end user that it is too low --#7
// If after 8 times they haven't guessed correctly then --#12
// Tell them they've lost the game --#11
int correctnumber = new Random().nextInt(100);
int numberOfGuesses = 8;
for (int i = 1; i <= numberOfGuesses; i++)
{
int chancesLeft = numberOfGuesses + 1 - i;
int guess = MessageBox.askForNumericalInput("Guess a number. (" + chancesLeft + " left)");
if (guess < 1 || 100 < guess)
MessageBox.showMessage("Your number " + guess + " is not between 1 and 100.");
if (guess == correctnumber)
{
Sounds.playBeep();
MessageBox.showMessage("You won!");
System.exit(0);
}
else if (correctnumber < guess)
{
MessageBox.showMessage("Too high.");
}
else
{
MessageBox.showMessage("Too low.");
}
}
MessageBox.showMessage("You lose. Correct answer: " + correctnumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import junit.framework.Assert;

import org.junit.Ignore;
import org.junit.Test;


public class Homework02
{
// 'How to do homework:
Expand All @@ -21,18 +19,18 @@ public class Homework02
public void youCanReadVariables() throws Exception
{
int numberOfDesserts = 5;
Assert.assertEquals(numberOfDesserts, ____);
Assert.assertEquals(numberOfDesserts, 5);
}
@Test
public void youCanSaveVariables() throws Exception
{
int ickynessOfBrothers = ____;
int ickynessOfBrothers = 10;
Assert.assertEquals(10, ickynessOfBrothers);
}
@Test
public void youCanDoMathWithVariables() throws Exception
{
int ____ = 3 + 4;
int numberOfHarryPotterBooks = 3 + 4;
Assert.assertEquals(7, numberOfHarryPotterBooks);
}
@Test
Expand All @@ -41,29 +39,29 @@ public void youCanChangeVariables() throws Exception
int milkTastiness = 6;
addChocolate();
milkTastiness = 10;
Assert.assertEquals(milkTastiness, ____);
Assert.assertEquals(milkTastiness, 10);
}
@Test
public void variablesAreSnotStuck() throws Exception
{
int boogers = 4;
blowNose();
boogers = ____;
boogers = 0;
Assert.assertEquals(0, boogers);
}
@Test
public void youCanAddToAVariable() throws Exception
{
int age = 11;
celebrateBirthday();
age += ____;
age += 1;
Assert.assertEquals(12, age);
}
@Test
public void youCanAddInMultipleWays() throws Exception
{
int bakersDozen = 12;
bakersDozen = bakersDozen + ____;
bakersDozen = bakersDozen + 1;
Assert.assertEquals(13, bakersDozen);
}
@Test
Expand All @@ -72,42 +70,42 @@ public void youCanAddOneInOneMoreWay() throws Exception
int bearsInABed = 3;
andTheLittleOneSaid("I'm lonely, come back here");
bearsInABed++;
Assert.assertEquals(bearsInABed, ____);
Assert.assertEquals(bearsInABed, 4);
}
@Test
public void youCanSubtractFromAVariable() throws Exception
{
int amountOfHomework = 3;
amountOfHomework -= ____;
amountOfHomework -= 3;
Assert.assertEquals(0, amountOfHomework);
}
@Test
public void youCanSubtractOneInOneMoreWay() throws Exception
{
int bottlesOfBeerOnTheWall = 99;
bottlesOfBeerOnTheWall--;
Assert.assertEquals(bottlesOfBeerOnTheWall, ____);
Assert.assertEquals(bottlesOfBeerOnTheWall, 98);
}
@Test
public void youCanMultiplyVariables() throws Exception
{
int volumeOfMyVoice = 2;
int volumeMyMomHears = volumeOfMyVoice * 5;
Assert.assertEquals(____, volumeMyMomHears);
Assert.assertEquals(10, volumeMyMomHears);
}
@Test
public void youCanDivideVariables() throws Exception
{
int inches = 36;
int feet = ____ / 12;
int feet = inches / 12;
Assert.assertEquals(3, feet);
}
@Test
public void variablesOnlyExistWithinTheMethod() throws Exception
{
String xmasList = "bike";
dreamBigger(); //This method is directly below
Assert.assertEquals(xmasList, ___);
Assert.assertEquals(xmasList, "bike");
}
private void dreamBigger()
{
Expand All @@ -117,7 +115,7 @@ private void dreamBigger()
public void methodsCanReturnValues() throws Exception
{
String bedPost = prepareForBed(); //This method is directly below
Assert.assertEquals(bedPost, ___);
Assert.assertEquals(bedPost, "gum");
}
public String prepareForBed()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
package org.teachingkidsprogramming.recipes.quizzes;

import org.teachingextensions.logo.Tortoise;
import org.teachingextensions.windows.MessageBox;
import org.teachingkidsprogramming.recipes.quizzes.graders.HiLowQuizGrader;

public class HiLowQuiz extends org.teachingkidsprogramming.recipes.quizzes.graders.HiLowQuiz
{
public void question1()
{
// if the Y position of the tortoise is 115
//
// turn the tortoise to the right 63 degrees
if (Tortoise.getY() == 115)
{
Tortoise.turn(63);
}
}
public void question2()
{
// if the X position of tortoise is less than Y position of tortoise
//
// turn the tortoise 54 degrees to the left
//
// otherwise turn the tortoise 22 degrees to the right
if (Tortoise.getX() < Tortoise.getY())
{
Tortoise.turn(-54);
}
else
Tortoise.turn(22);
}
public void question3()
{
// display the message "elcomeway omehay!"
MessageBox.showMessage("elcomeway omehay!");
}
public void question4()
{
// if the Y position of tortoise is greater than 50
//
// turn the tortoise 177 degrees to the left
if (Tortoise.getY() > 50)
{
Tortoise.turn(-177);
}
}
public static void main(String[] args)
{
Expand Down