My Pets

Objective

  1. Gain a deeper understanding of object relations.
  2. Build classes that produce objects that interact with one another through associations and behavior.

Instructions

This is a test-driven lab. Use the test file and test output to understand what is being asked of you as you follow the guidelines below.

Overview

You will be building an Owner, Dog, and Cat class. An Owner will know about all their pets, be able to buy a pet, change a pet's mood through walking or feeding it, and sell all of their pets (for when they move to that tiny NYC studio after college).

A Dog and a Cat are initialized with a name and an Owner object

Part I: Object Models

  • Define a Dog and Cat class that have the attributes required by the test suite. Keep in mind, some of the attributes should be readable and writable (i.e. attr_accessors), while others may need to be just setters (attr_writer) or just getters (attr_reader). The test suite will make this clear so pay attention to the test output.

Part II: Object Relations

  • An owner should be able to buy and sell a pet, which will change the pet's mood.

  • When an owner buys a new pet, the buy_cat/buy_dog methods take in an argument of a name. You must take that name and do the following:

    • Make a new instance of the appropriate pet, initializing it with that name and the owner who is purchasing it.
  • An owner should have the ability to walk all their dogs or feed all their cats, which will change the mood of all of their pets of that type to "happy".

Owner, Dogs and Cats

These are just a few hints and guidelines to help you through this lab. This lab is extensive and challenging. Rely on the guides here, refer to the previous Code Along on object relations, and read the test output and test files. Never forget to ask a question on Learn if you are stuck. And remember, as a programmer, your job is to fix broken code! Broken code is the norm, the baseline, the starting point for all of the projects you will build. Embrace it!

View OO My Pets on Learn.co and start learning to code for free.