CS 161 Assignment #1

Due Monday, January 22nd by 11:59pm
(Not accepted after 1/24)

Introduction

This first assignment will give you a chance to explore the shape classes in more detail, and gain additional experience with BlueJ. You'll start by recording the steps required to build a particular scene out of circle objects, then answer some questions about the Java code implementing those shapes.

The Assignment

  1. In the first lab, you followed a set of steps that I provided to build a simple house out of a square and a triangle. Create a similar "recipe" that describes how to create the bullseye diagram shown below. Your recipe does not need to be actual, executable Java — an informal list of steps like the house example on the lab is fine. (Your bullseye should be at the position specified below, and the circles should be lined up properly with appropriate sizes, with the same colors as the one in the picture.)

    The bullseye is made up of three different Circle objects. The outer has a size of 100, the middle circle has a size of 60, and the inner circle is of size 20. The largest circle's X and Y positions are both 50, and the other circles' centers line up with the outer circle. Your recipe should give names to each of the circles (like the lab did), and use those names in later steps to be specific about which circles' behaviors are being executed. For full credit, you should try to come up with the shortest sequence of steps that will create the bullseye. You may not modify the Circle class — your recipe should work with the version of the Circle class that's in the UPS_figures project we worked with in lab.

  2. Open the Triangle class and look at its source code. How many fields are there? How many different kinds of information are stored in those fields? (E.g. numbers, words, etc.)
  3. Many of the methods in Triangle call other methods. For example, makeInvisible calls erase(), and moveHorizontal calls both erase() and draw(). Which methods (including the constructor) in Triangle do not call other methods?
  4. Which of the methods (including the constructor) in Triangle change xPosition? (We'll consider xPosition to be changed by a method if it potentially has a different value after the method is called, so a method can change xPosition without necessarily referring to xPosition by name — it could call some other method that changes xPosition, for example.) If in doubt, try it out in BlueJ: Create a Triangle and use the object inspector (double click the triangle object) to see its fields. Run a method, and see if xPosition changes.

Submitting

Please type up your solutions so I have some hope of reading them, and save them either a plain text file or, preferably, as a PDF. Name the file after yourself (e.g. richards-asmt1.pdf), and attach it to an email to me at brichards@pugetsound.edu.


Brad Richards, 2024