teaching machines

CS 145 Lab 6 – Objects

November 29, 2015 by . Filed under cs145, fall 2015, labs.

First, if you have checkpoints left over from last lab, get them inspected during the first 15 minutes of this lab. No credit will be awarded past these 15 minutes.

Don’t forget to work in pairs! Where possible, please work with someone that you did not work with last week. The exchange of new ideas and perspectives is not an opportunity of which you want to rob yourself.

Objective

In this lab you will learn about bundling data and its related code into objects. Large software is built out of hundreds of interacting objects, each of which is managing a small chunk of a complex task.

Checkpoint 1

Person A types.

Write an object to represent two-dimensional  Points. Include the following:

Now write a main method that produces a spiral:

  1. construct a point at the origin
  2. translate it 5 units on the x-axis
  3. repeatedly rotate and scale the point

After each rotate/scale transformation, print it to the console, separating each x, y with a linebreak. Paste the result list into Desmos.

Checkpoint 2

Person B types.

Write a class RoundRobinList that can be used to repeatedly and fairly cycle through a list of people or things. Include the following:

Also write a main method that constructs a RoundRobinList, adds some names, and rotates through it a few times. Print the names.

For example, if you create a list and add to it apple, banana, and carbonite, you’ll generate the following sequence when you call rotate 8 times:

carbonite
banana
apple
carbonite
banana
apple
carbonite
banana