Instantly share code, notes, and snippets.

@alexdunae /week3.markdown Secret
Last active Aug 29, 2015

Embed
What would you like to do?
Week 3 Assignment - Dog Park

Week 3 Code Assignment

Create a file named park.rb. Up at the top of the file you'll define your classes. Down at the bottom you'll actually initialize the classes and run code.

Before you submit, make sure you've written some code down at the bottom of your file showing me how it works.

When you're done, create a new Gist with your code and email it to me.

Dog Class

Create a class named Dog with two instance methods: run and is_running?. Make it so we can assign each dog a name and a breed. Name and breed should be strings.

If a dog's run method has NOT been called, is_running? should return false. If it has been called, is_running? should return true.

Child Class

Create a class named Child with two instance methods: run and is_running?. Make it so we can assign each child a name and an age. Name should be a string, but age should be a number.

Just like with the Dog class, if a child's run method has NOT been called, is_running? should return false. If it has been called, is_running? should return true.

Park Class

Create a class named Park. Write a method to let us add Dog instances to the park. Write a different method to let us a Child instances to the park.

On your Park class add three instance methods:

  • all_dogs should print each dog's name and breed, e.g. Fido is a labrador
  • all_children should print each child's name and age, e.g. Jimmy is 6 years old
  • who_is_running should print the names of both children and dogs that are running, as well as what type they are, e.g. Jimmy the child is running

Bonus

Your Child and Dog classes will have some duplicate code. See if you can take that duplicate code, put it into a module and use include to mix it into the classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment