diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..e794567
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f1c34ea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.settings/
+bin/
+.DS_Store
\ No newline at end of file
diff --git a/.project b/.project
new file mode 100644
index 0000000..5b72d8a
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ Lesson5
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/doc/Gridworld Reference.pdf b/doc/Gridworld Reference.pdf
new file mode 100644
index 0000000..ae9748e
Binary files /dev/null and b/doc/Gridworld Reference.pdf differ
diff --git a/lib/Tortoise.jar b/lib/Tortoise.jar
new file mode 100644
index 0000000..2ea93a5
Binary files /dev/null and b/lib/Tortoise.jar differ
diff --git a/lib/gridworld.jar b/lib/gridworld.jar
new file mode 100644
index 0000000..58c20e4
Binary files /dev/null and b/lib/gridworld.jar differ
diff --git a/sounds/patrick.wav b/sounds/patrick.wav
new file mode 100644
index 0000000..eea32cc
Binary files /dev/null and b/sounds/patrick.wav differ
diff --git a/sounds/quack.wav b/sounds/quack.wav
new file mode 100644
index 0000000..bb84664
Binary files /dev/null and b/sounds/quack.wav differ
diff --git a/sounds/spongebob.wav b/sounds/spongebob.wav
new file mode 100644
index 0000000..eb0ebc3
Binary files /dev/null and b/sounds/spongebob.wav differ
diff --git a/sounds/squidward.wav b/sounds/squidward.wav
new file mode 100644
index 0000000..eebdb29
Binary files /dev/null and b/sounds/squidward.wav differ
diff --git a/src/examples/Athlete.java b/src/examples/Athlete.java
new file mode 100644
index 0000000..bbdb1c6
--- /dev/null
+++ b/src/examples/Athlete.java
@@ -0,0 +1,30 @@
+package examples;
+
+public class Athlete {
+
+ private String name;
+ private int speed;
+ private static String location;
+ private int bibNumber;
+ private static int numberOfRunners;
+
+ public Athlete(String name, int speed) {
+ this.name = name;
+ this.speed = speed;
+ this.bibNumber = numberOfRunners++;
+ }
+
+ @Override
+ public String toString() {
+ return name + " " + speed + " at " + location + ", bib number " + this.bibNumber;
+ }
+
+ public void setLocation(String string) {
+ this.location = string;
+ }
+
+ public static int getNumberOfRunners() {
+ return numberOfRunners;
+ }
+
+}
diff --git a/src/examples/Disease.java b/src/examples/Disease.java
new file mode 100644
index 0000000..f58ac26
--- /dev/null
+++ b/src/examples/Disease.java
@@ -0,0 +1,27 @@
+package examples;
+
+public class Disease {
+
+ //instance variables
+ private String name;
+ private boolean curable;
+
+ Disease(String title, boolean isCurable){
+ this.curable = isCurable;
+ this.name = title;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isCurable() {
+ return curable;
+ }
+
+
+ void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/src/examples/DiseaseSorter.java b/src/examples/DiseaseSorter.java
new file mode 100644
index 0000000..edcd419
--- /dev/null
+++ b/src/examples/DiseaseSorter.java
@@ -0,0 +1,27 @@
+package examples;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DiseaseSorter {
+
+ public static void main(String[] args) {
+ Disease polio = new Disease("polio", false);
+ Disease flu = new Disease("influenza", true);
+ Disease tuberculosis = new Disease("tuberculosis", false);
+
+ List diseases = new ArrayList();
+ diseases.add(polio);
+ diseases.add(flu);
+ diseases.add(tuberculosis);
+
+ /* print all the incurable diseases */
+ for (Disease disease : diseases) {
+ if (!disease.isCurable()) {
+ System.out.println(disease.getName());
+ }
+ }
+
+ }
+
+}
diff --git a/src/examples/Duck.java b/src/examples/Duck.java
new file mode 100644
index 0000000..1e5a6ea
--- /dev/null
+++ b/src/examples/Duck.java
@@ -0,0 +1,42 @@
+package examples;
+
+import java.io.File;
+
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+
+public class Duck {
+
+ private String favoriteFood;
+ private int lifeExpectancy;
+
+
+ public Duck(String favoriteFood, int lifeExpectancy) {
+ this.favoriteFood = favoriteFood;
+ this.lifeExpectancy = lifeExpectancy;
+ }
+
+ public void waddle() {
+ lifeExpectancy++;
+ System.out.println("waddle waddle");
+ }
+
+ @Override
+ public String toString() {
+ return "This duck likes to eat " + this.favoriteFood + " and will live to be " + this.lifeExpectancy + ".";
+ }
+
+ public void quack() {
+ try {
+ AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("sounds/quack.wav"));
+ Clip clip = AudioSystem.getClip();
+ clip.open(audioInputStream);
+ clip.start();
+ Thread.sleep(3400);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/examples/DuckBreeder.java b/src/examples/DuckBreeder.java
new file mode 100644
index 0000000..d683312
--- /dev/null
+++ b/src/examples/DuckBreeder.java
@@ -0,0 +1,33 @@
+package examples;
+
+public class DuckBreeder {
+ public static void main(String[] args) {
+
+
+// Duck morrisey = new Duck("celery", 90/3);
+//
+// Duck carniverousCarla = new Duck("frogs", 60/3);
+//
+// carniverousCarla.waddle();
+// carniverousCarla.waddle();
+// carniverousCarla.waddle();
+//
+// System.out.println(morrisey);
+//
+// System.out.println(carniverousCarla);
+//
+// morrisey.quack();
+// morrisey.quack();
+
+
+
+ // 1. Create an instance of a Duck called Daffy
+ // =
+ Duck daffy = new Duck("", 0);
+
+ // 2. Get Daffy to quack
+
+ daffy.quack();
+
+ }
+}
diff --git a/src/examples/Marathon.java b/src/examples/Marathon.java
new file mode 100644
index 0000000..dd49d0f
--- /dev/null
+++ b/src/examples/Marathon.java
@@ -0,0 +1,21 @@
+package examples;
+
+public class Marathon {
+
+//Athletes:
+ //instance specific data: name, speed
+ //static data: number of runners, location of marathon
+
+ public static void main(String[] args) {
+ Athlete john = new Athlete("john", 10);
+ Athlete betsy = new Athlete("betsy", 12);
+
+ john.setLocation("San Diego");
+ betsy.setLocation("London");
+ System.out.println(betsy);
+ System.out.println(john);
+
+ System.out.println("Runners in race: " + Athlete.getNumberOfRunners());
+ }
+
+}
diff --git a/src/examples/MessingAroundWithJUnit.java b/src/examples/MessingAroundWithJUnit.java
new file mode 100644
index 0000000..1476099
--- /dev/null
+++ b/src/examples/MessingAroundWithJUnit.java
@@ -0,0 +1,14 @@
+package examples;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class MessingAroundWithJUnit {
+
+ @Test
+ public void testName() throws Exception {
+ assertEquals(4, 2+2);
+
+ }
+}
diff --git a/src/exercises/Cat.java b/src/exercises/Cat.java
new file mode 100644
index 0000000..522941b
--- /dev/null
+++ b/src/exercises/Cat.java
@@ -0,0 +1,46 @@
+package exercises;
+
+public class Cat {
+
+ private String name;
+ private int lives = 9;
+
+ Cat(String name) {
+ this.name = name;
+ }
+
+ void meow() {
+ System.out.println("meeeeeooooooooooowwwwwwwww!!");
+ }
+
+ public void printName() {
+ if (name == null)
+ System.out.println("i don't know my own name!");
+ else
+ System.out.println("my name is " + name);
+ }
+
+ void kill() {
+ lives--;
+ if (lives > 0)
+ System.out.println("nice try, but I still have " + lives + " lives left");
+ else if (lives < 0)
+ System.out.println("that's overkill yo!");
+ else
+ System.out.println("DEAD CAT :(");
+ }
+
+ public static void main(String[] args) {
+ /* Do the following things without changing the Cat class */
+
+ // 1. Make the Cat meow
+
+ // 2. Get the Cat to print it's name
+
+ // 3. Kill the Cat!
+
+ }
+}
+
+
+
diff --git a/src/exercises/Gridworld.java b/src/exercises/Gridworld.java
new file mode 100644
index 0000000..7063843
--- /dev/null
+++ b/src/exercises/Gridworld.java
@@ -0,0 +1,14 @@
+package exercises;
+/*
+ * Use the Gridworld Reference document in the "doc" directory to complete the following tasks;
+ *
+ * 1. Figure out how to get the World to show.
+ * 2. Figure out how to add a Bug to the world (clue: you will need the Bug and Location objects)
+ * 3. Add another bug at a random location in the world.
+ * 4. Change the color of that bug to blue.
+ * 5. Make the bug face to the right.
+ * 6. Add flowers to the left and right of the bug.
+ * 7. Fill the whole world with flowers!
+*/
+
+public class Gridworld {}
diff --git a/src/exercises/HarryPotter.java b/src/exercises/HarryPotter.java
new file mode 100644
index 0000000..ed85574
--- /dev/null
+++ b/src/exercises/HarryPotter.java
@@ -0,0 +1,36 @@
+package exercises;
+
+public class HarryPotter {
+
+ private boolean cloakOn;
+
+ HarryPotter() {
+ System.out.println("making Harry Potter...");
+ }
+
+ void castSpell(String spell) {
+ System.out.println("casting spell: " + spell);
+ }
+
+ void makeInvisible(boolean invisible) {
+ this.cloakOn = invisible;
+
+ if (cloakOn)
+ System.out.println("Harry is invisible");
+ else
+ System.out.println("Harry is visible");
+ }
+
+ void spyOnSnape() {
+ System.out.println("Harry sees Professor Snape doing nefarious things.");
+ }
+
+ public static void main(String[] args) {
+ // 1. make harry potter
+ // 2. become invisible
+ // 3. spy on professor snape
+ // 4. become visible again
+ // 5. cast a “stupefy” spell
+ }
+
+}
diff --git a/src/exercises/MinionTest.java b/src/exercises/MinionTest.java
new file mode 100644
index 0000000..b3fadeb
--- /dev/null
+++ b/src/exercises/MinionTest.java
@@ -0,0 +1,50 @@
+package exercises;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * To make these tests pass, you will need to create a Minion class with the member variables below.
+ *
+ *
+ * private String name;
+ * private int eyes;
+ * private String color;
+ * private String master;
+ *
+ *
+ * Create a constructor, and getters and setters for the member variables. If they’re done right, these tests will pass.
+ *
+ * **/
+
+public class MinionTest {
+
+// @Test
+// public void testConstructor() {
+// Minion stuart = new Minion("Stuart", 1, "yellow", "");
+// assertEquals("Stuart", stuart.getName());
+// assertEquals(1, stuart.getEyes());
+// assertEquals("yellow", stuart.getColor());
+//
+// Minion dave = new Minion("Dave", 2, "yellow", "");
+// assertEquals("Dave", dave.getName());
+// assertEquals(2, dave.getEyes());
+// assertEquals("yellow", dave.getColor());
+// }
+//
+// @Test
+// public void testSetters() {
+// Minion stuart = new Minion("Stuart", 1, "yellow", "");
+//
+// stuart.setMaster("T. Rex");
+// assertEquals("T. Rex", stuart.getMaster());
+//
+// stuart.setMaster("Napoleon");
+// assertEquals("Napoleon", stuart.getMaster());
+// }
+
+}
+
+
+
diff --git a/src/exercises/Smurf.java b/src/exercises/Smurf.java
new file mode 100644
index 0000000..480f404
--- /dev/null
+++ b/src/exercises/Smurf.java
@@ -0,0 +1,41 @@
+package exercises;
+
+/*
+ * 1. Watch this smurf cartoon: https://www.youtube.com/watch?v=RqbpzEHuO2g
+ * 2. In a Runner class, make a Handy Smurf. Use the methods below to make him eat, and print his name.
+ *
+ * 5. Make a Papa Smurf and print his name, hat color and girl or boy.
+ * 6. Make a Smurfette and print her name, hat color and girl or boy. */
+
+public class Smurf {
+
+ private String name;
+
+ Smurf(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return "My name is " + name + " Smurf.";
+ }
+
+ public void eat() {
+ System.out.println(name + " Smurf is eating Smurfberries.");
+ }
+
+ /* Papa Smurf wears a red hat, all the others are white. */
+ public String getHatColor() {
+ // 3. Fill in this method
+ return "";
+ }
+
+ /* Smurfette is the only female Smurf. */
+ public String isGirlOrBoy() {
+ // 4. Fill in this method
+ return "";
+ }
+
+}
+
+
+
diff --git a/src/exercises/StaticDucks.java b/src/exercises/StaticDucks.java
new file mode 100644
index 0000000..b83ec9f
--- /dev/null
+++ b/src/exercises/StaticDucks.java
@@ -0,0 +1,29 @@
+package exercises;
+
+import examples.Duck;
+import junit.framework.TestCase;
+
+public class StaticDucks extends TestCase {
+
+// public void testWeCanCountTheNumberOfDucksCreated() throws Exception {
+// assertEquals(0, Duck.getNumberOfCreations());
+// Duck duck1 = new Duck();
+// Duck duck2 = new Duck();
+// Duck duck3 = new Duck();
+// assertEquals(3, Duck.getNumberOfCreations());
+// Duck duck4 = new Duck();
+// assertEquals(4, Duck.getNumberOfCreations());
+// }
+//
+// public void testEverySecondDuckIsBlack() throws Exception {
+// Duck duck1 = new Duck();
+// Duck duck2 = new Duck();
+// Duck duck3 = new Duck();
+// assertEquals("black", duck1.getColor());
+// assertEquals("white", duck2.getColor());
+// assertEquals("black", duck3.getColor());
+// }
+//
+// public void testEveryFourJellyfishArePoisonous() throws Exception {
+// }
+}
diff --git a/src/optional/Backpack.java b/src/optional/Backpack.java
new file mode 100644
index 0000000..1200846
--- /dev/null
+++ b/src/optional/Backpack.java
@@ -0,0 +1,86 @@
+package optional;
+
+
+public class Backpack {
+
+ private Pencil pencil;
+ private Ruler ruler;
+ private Textbook textbook;
+
+ Backpack(){
+ System.out.println("Nice Backpack");
+ }
+
+ public static void main (String[] args){
+ /* Your mission is to get to school, but first you need to get all of your supplies into your backpack. */
+
+
+
+ }
+
+ public void putInBackpack(Supply supply){
+ if (supply instanceof Pencil){
+ this.pencil = (Pencil) supply;
+ System.out.println("You put your pencil in your Backpack");
+ }else if(supply instanceof Ruler){
+ this.ruler = (Ruler) supply;
+ System.out.println("You put your ruler in your Backpack");
+ }else if(supply instanceof Textbook){
+ this.textbook = (Textbook) supply;
+ System.out.println("You put your textbook in your Backpack");
+ }else{
+ System.out.println("That isn't a valid school supply");
+ }
+ }
+
+ public void goToSchool(){
+ if(pencil == null || ruler == null || textbook == null){
+ System.err.println("You are not ready for School");
+ }else{
+ System.out.println("Congratulations! You are ready for school");
+ }
+ }
+}
+
+class Supply {
+ protected String name;
+}
+
+class Pencil extends Supply {
+
+ Pencil(){
+ this.name = "pencil";
+ System.out.println("You got your pencil!");
+ }
+
+ public void write(String writing){
+ System.out.println(writing);
+ }
+}
+
+
+class Ruler extends Supply {
+
+ Ruler(){
+ this.name = "ruler";
+ System.out.println("You found your ruler!!");
+ }
+
+ public void measure(){
+ System.out.println("Now you can measure your mouse!");
+ }
+}
+
+class Textbook extends Supply{
+
+ Textbook(){
+ this.name = "textbook";
+ System.out.println("You got your boring textbook");
+ }
+
+ public void read(){
+ System.out.println("The history of Iceland is long and interesting");
+ }
+}
+
+
diff --git a/src/optional/LandOfTurtles.java b/src/optional/LandOfTurtles.java
new file mode 100644
index 0000000..c14bc9f
--- /dev/null
+++ b/src/optional/LandOfTurtles.java
@@ -0,0 +1,27 @@
+package optional;
+
+import javax.swing.JFrame;
+import org.teachingextensions.logo.MultiTurtlePanel;
+import org.teachingextensions.logo.Turtle;
+
+public class LandOfTurtles {
+ public static void main(String[] args) {
+ MultiTurtlePanel panel = new MultiTurtlePanel();
+ String galapagosIslands = "https://farm2.staticflickr.com/1104/752631367_5c5d474ba5_o.jpg";
+
+ // 1. Instantiate a JFrame object & make it visible
+
+ // 2. Add the panel to the frame
+
+ // 3. Set the background image of the panel to the Galapagos Islands
+
+ //4. Set the size image of the frame to 600 by 400
+
+ // 5. Instantiate a Turtle
+
+ // 6. Add the turtle to the panel
+
+ // 7. Put 50 Turtles on the beach
+
+ }
+}
diff --git a/src/optional/Platypus.java b/src/optional/Platypus.java
new file mode 100644
index 0000000..9388052
--- /dev/null
+++ b/src/optional/Platypus.java
@@ -0,0 +1,19 @@
+package optional;
+
+public class Platypus {
+ private String name;
+
+ void sayHi(){
+ System.out.println("The platypus " + name + " is smarter than your average platypus.");
+ }
+
+ public static void main(String[] args) {
+ //1. Make an instance of your new pet platypus
+
+ //2. Call the sayHi method
+
+ //3. Create a constructor in the platypus class so that you can give your platypus a name.
+ }
+}
+
+
diff --git a/src/optional/Popcorn.java b/src/optional/Popcorn.java
new file mode 100644
index 0000000..53a3d43
--- /dev/null
+++ b/src/optional/Popcorn.java
@@ -0,0 +1,67 @@
+package optional;
+
+/* Your mission and you have to accept it:
+ * Add a main method to the Popcorn class to cook a bag of Popcorn. Don't change the existing methods.
+ */
+
+class Microwave {
+ private int cookTime;
+ Popcorn thingToBeCooked;
+
+ Microwave() {
+ System.out.println("Microwave says: a Microwave has been made.");
+ }
+
+ void putInMicrowave(Popcorn thingToBeCooked) {
+ System.out.println("Microwave says: popcorn put in microwave.");
+ this.thingToBeCooked = thingToBeCooked;
+ }
+
+ void setTime(int cookTimeInMinutes) {
+ System.out.println("Microwave says: cook time is set to " + cookTime + " minutes.");
+ this.cookTime = cookTimeInMinutes;
+ }
+
+ void startMicrowave() {
+ if (thingToBeCooked == null)
+ System.out.println("Microwave says: there's nothing in the microwave!");
+ for (int i = 0; i < cookTime*10 + 1; i++) {
+ thingToBeCooked.applyHeat();
+ }
+ }
+}
+
+public class Popcorn {
+
+ private int kernels = 20;
+ private String flavor;
+
+ Popcorn(String flavor) {
+ this.flavor = flavor;
+ System.out.println("Popcorn says: making package of " + this.flavor + " popcorn.");
+ }
+
+
+ public void applyHeat() {
+ pause();
+
+ if (kernels == 0) {
+ System.out.println("Popcorn says: Time to eat popcorn!");
+ } else {
+ System.out.println("POP!" + kernels);
+ kernels--;
+ }
+ }
+
+ private void pause() {
+ try {
+ Thread.sleep(150);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
+
+
+
diff --git a/src/optional/SeaCreature.java b/src/optional/SeaCreature.java
new file mode 100644
index 0000000..d344f4b
--- /dev/null
+++ b/src/optional/SeaCreature.java
@@ -0,0 +1,48 @@
+package optional;
+
+/*
+ * 1. In a Runner class, make a SeaCreature called “Spongebob”. Use the methods below to make him eat, and laugh.
+ * 2. Make Patrick and Squidward and print their name, have them eat, and make them laugh.
+ */
+
+import java.io.File;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+
+public class SeaCreature {
+
+ public static void main(String[] args) {
+ SeaCreature spong = new SeaCreature("squidward");
+ spong.laugh();
+ }
+
+
+ private String name;
+
+ SeaCreature(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return "My name is " + name;
+ }
+
+ public void eat() {
+ System.out.println(name + " is eating krabby patties");
+ }
+
+ public void laugh() {
+ try {
+ AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(
+ "sounds/" + this.name + ".wav").toURI().toURL());
+ Clip clip = AudioSystem.getClip();
+ clip.open(audioInputStream);
+ clip.start();
+ Thread.sleep(3400);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/optional/TeaMaker.java b/src/optional/TeaMaker.java
new file mode 100644
index 0000000..13081b3
--- /dev/null
+++ b/src/optional/TeaMaker.java
@@ -0,0 +1,65 @@
+package optional;
+
+public class TeaMaker {
+
+ /* Figure out how to make a cup of tea using the classes below */
+
+}
+
+class TeaBag {
+
+ public final static String GREEN = "Green";
+ public final static String MINT = "Mint";
+ public final static String CHAMOMILE = "Chamomile";
+ public final static String PASSION_FRUIT = "Passion Fruit";
+
+ private String flavor;
+
+ TeaBag(String flavor) {
+ this.flavor = flavor;
+ }
+
+ String getFlavor() {
+ return flavor;
+ }
+
+}
+
+class Kettle {
+
+ private Water water = new Water();
+
+ Water getWater() {
+ return water;
+ }
+
+ void boil() {
+ this.water.isHot = true;
+ }
+
+ class Water {
+
+ private boolean isHot = false;
+
+ public boolean isHot() {
+ return this.isHot;
+ }
+ }
+
+}
+
+class Cup {
+
+ private TeaBag teabag;
+
+ void makeTea(TeaBag teabag, Kettle.Water hotWater) {
+ this.teabag = teabag;
+ if (hotWater.isHot())
+ System.out.println("Making hot " + teabag.getFlavor() + " tea.");
+ else
+ System.out.println("Can't make tea with cold water! ");
+ }
+
+}
+
+
diff --git a/src/optional/TeaPartyTest.java b/src/optional/TeaPartyTest.java
new file mode 100644
index 0000000..0d516bc
--- /dev/null
+++ b/src/optional/TeaPartyTest.java
@@ -0,0 +1,21 @@
+package optional;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+public class TeaPartyTest {
+ /**
+ * Jane Austen is a women, so say “Hello Ms. Austen”.
+ * George Orwell is a man, so say “Hello Mr. Orwell”.
+ * Isaac Newton was knighted, so say "Hello Sir Newton".
+ **/
+
+// @Test
+// public void test() {
+// TeaParty teaParty = new TeaParty();
+// String greeting = teaParty.welcome(null, false, false);
+// assertEquals("Hello Ms. Austen", teaParty.welcome("Austen", true, false));
+// assertEquals("Hello Mr. Orwell", teaParty.welcome("Orwell", false, false));
+// assertEquals("Hello Sir Newton", teaParty.welcome("Newton", false, true));
+// }
+}