APCS Unit 4: Object Oriented Design

Using classes and objects to organize your programs

OBJECT ORIENTED DESIGN OVERVIEW

Control structures are an essential element of any program.  As our programs get larger and larger however, the idea of classes and objects can really do a lot to help us organize our logic and information.  When we programmed in Jeroo, the Jeroo class was used to keep track of the location, direction, and number of flowers a Jeroo was holding.  Then, we were able to use the various methods of a Jeroo (hopping, picking, planting) to make it interact with the world.  In this way, the Jeroo class and Jeroo objects allowed us to interact more intuitively with the program.

In this unit, we’ll get an introduction to the way classes are built.  We’ll also start to see how to make classes work together, and how to write classes that have all three main components:  variables, constructors, and methods.  By the end of the unit, you’ll have a sense for how these different elements come together to make object oriented design possible!

PART 1: CLASSES & CONSTRUCTORS

(30 pts)  About 3 days

We start with an introduction to what a class is and how classes use variables and constructors to setup the initial values of an object.  You’ll get to write a variety of simple classes and use a Driver (Runner) class to test them out.  We’ll also get our first taste of codingbat – a website that lets us practice writing methods!

PART 2: GETTERS, SETTERS & MUTATORS

(40 pts)  About 3 days

Classes are great at storing information, but it’s the methods that really make things happen!  Here you’ll learn how to write getter and setter methods to interact with the variables of your class.  We’ll also start to write our own mutators that will let us interact with objects in other ways.

PART 3: LHS ZOO

(30 pts)  About 3 days

The final part of our unit will have you build a larger zoo program.  This zoo will have the job of keeping track of animals, supplies, and employees for the brand new Lathrop Zoo!  In doing so, you’ll create classes, variables, constructors, and methods that let a user talk to the program and keep track of what’s going on in our busy zoo.

PART 1: Classes & Constructors

Developing our first custom classes

As we get started in this unit, the first job is to look at creating new classes.  Classes are ways for us to organize the logic of a program into groups of variables and methods.  These groups of variables and methods (like Jeroos) will give us the control we need to make special things happen in a program.  For this to all work together, we first need to organize the parts (nouns) of our program into specific classes along with relevant variables, constructors, and methods!

Creating Classes

Constructors

Multi-Argument Constructors

What’s Due In Object Oriented Design Part 1: Classes & Constructors

  • OOD Notes
  • Constructor Notes
  • 6 Java Tasks
  • 6 CodingBat Challenges
  • Benshoof’s Check-Off

Here’s what’s due in Part 1: Wiring

  1.  Notes on Object Oriented Design
  2.  Notes on Constructors of different kinds, including the ones you write!
  3. Complete the 6 Java Tasks by creating the described constructors
  4. Complete 6 CodingBat.com challenges from the Warm-Up #1 section
  5.  Have Benshoof check-off your working wiring

PART 2: Setters, Getters & Mutators

Writing methods to interact with classes

With the framework of classes under control, it’s time to start writing different kinds of methods to interact with our classes and objects in new ways.  Classes start with a class signature, and then are made more useful when we add class variables and constructors.  Once that is complete, we need to be able to make three kinds of methods:  setters, getters, and mutators.

  • SETTERS: We always make our class variables private.  This means that the only thing that can set or re-set them within an object is the object itself.  Thus, we need to make a method – called a ‘setter’ – that can set (or reset) the value of a variable to something new.
  • GETTERS: Again, because all our variables are private, we need a method in order to interact with variables.  ‘Getters’ are the simple methods that just return the value of a variable so that other classes can use it.
  • MUTATORS:  These methods are the more complex ones that actually make things happen within a class.  Sometimes these update class variables to represent new situations, and other times they actually make things happen on the screen.

In this part of the unit, you’ll learn to write each of these kinds of methods and will actually put them into practice!

Getters & Setters

Static Methods

More About Methods

What’s Due In Object Oriented Design Part 2: Setters, Getters & Mutators

  • Methods Notes
  • 6 Java Tasks
  • 6 CodingBat Challenges
  • Benshoof’s Check-Off

Here’s what’s due in Part 2: Setters, Getters & Mutators

  1.  Take a full page of notes on the different kinds of methods and how they are written
  2. Complete all 6 Java Tasks that ask you to write classes with setters, getters, and mutators
  3. Complete 6 CodingBat challenges from the Strings #1 group
  4.  Have Benshoof check-off your careful drawing

PART 3: LHS Zoo

Create a large class structure to keep track of our own Zoo!

Soldering – how to!  Give some thoughts and notes that summarize the big ideas

What’s Due In Bug Bot Part 3: Build It!

  • Build It
  • (Extra Credit) Decorate it
  • Benshoof’s Check-Off

Here’s what’s due in Part 3: Build It!

  1.  Get into the makerspace and build your Bug Bot!  Make sure it functions properly!
  2.  If you have extra time, give your Bug Bot that special touch by painting, lasering, or making stickers to customize it!
  3.  Have Benshoof check-off your finished, working Bug Bot

Double Check: Unit Expectations

Check what you need to have completed by the unit deadline

The purpose of this unit is to use the Engineering Design Process to wire, design, and build a working Bug Bot.  You should have had the chance to do some soldering, design your own Bug Bot, and use the tools in our makerspace to build your Bug Bot.  If you were really on-task and working hard, you should have also had time to decorate your Bug Bot to make it look super cool.  By the unit deadline, you should have completed and be able to submit the following items:

Engineering Notebook:

 (Part 1) Definition of problem, criteria, constraints, and Bug Bot Overview notes

 (Part 1) Wiring diagram, soldering notes, and wiring reflection

 (Part 2) Bug Bot Design brainstorm, notes, and careful drawing

 (Part 3) Final drawing/picture, half-page written reflection on Bug Bots

Building & Making:

 (Part 1) Wiring should work, soldering should be clean and complete

 (Part 2) Bug Bot design should be carefully drawn out including labels and diagrams

 (Part 3) The Bug Bot should be assembled and should function properly

Benshoof Checkpoints

 (Part 1) Benshoof should have seen your working wiring before you moved on

 (Part 2) Benshoof should have seen your careful drawing before you moved on

 (Part 3) Benshoof should have seen your working Bug Bot