AP CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Monday, October 29
Description
Order of Magnitude Analysis
Homework
  • Create a project that contains the following three files:

    • An interface called Shape that defines two methods:

      /**
       * Returns the permimeter of this object by adding up the lengths of all
       * the sides of the current object.
       *
       * @return The perimeter of this object
       */
      public double getPermimeter()
      
      
      /**
       * Returns the two-dimensional area of this object, computed from the
       * dimensions of the object.
       *
       * @return The area of this object
       */
      public double getArea()
      
    • A class named RightTriangle that implements the Shape interface. It represents a right triangle, and should have a constructor that takes the base, height, and hypotenuse of the triangle (each a double). It must implement the methods of the Shape interface correctly.
    • A class named Rectangle that implements the Shape interface. It represents a rectangle (a 4-sided shape with 90-degree angles at each corner), and should have a constructor that takes the width and height of the rectangle (each a double). It must implement the methods of the Shape interface correctly.

    Your code should be properly commented and free of syntax errors. Archive the project and e-mail it to me before the start of next class.

Tuesday, October 30
Description
Practice Test
Homework
  • Tonight we begin work on the Towers of Hanoi. This is a well-known problem, and there are solutions all over the internet. I want you to discover the solution to the puzzle on your own; please attempt the homework below without searching for solutions online.
  • The Legend of the Towers of Hanoi says that there is a monestary in Hanoi with three giant diamond spires, and a collection of 64 golden discs. When the monestary was built, the 64 discs were stacked on the leftmost spire with the largest on the bottom and the smallest at the top.

    Once an hour, the monks in the monestary move a single disc from one spire to another in an attempt to stack all the discs on the rightmost spire. In doing so, they must observe the following rules:

    1. Only one disc may be moved at a time; it can go to any spire, so long as
    2. A larger disc is never be placed on top of a smaller disc

    According to the legend, if the monks are able to solve the puzzle, the universe will come to an end. So:

    1. Can the puzzle even be solved with 64 discs?
    2. If it is possible to solve, should we be concerned about the universe ending? (In other words, how long will the puzzle take to solve if the monks move one disc per hour?)
  • To help you figure out the answers to those questions, I've provided a simplified version of the puzzle (with fewer discs) below:

  • For next class:

    1. Figure out how to solve the puzzle for 3 discs using the simulation above. Hand-write complete instructions for solving the puzzle for 3 discs. You should include every move of every disc, and include the starting and ending tower in each move. Someone who has never seen the game before should be able to follow your directions to solve the 3-disc case. I recommend numbering the discs from 1 (smallest) to 3 (largest). Label the towers "L" (left), "C" (center), and "R" (right). You're trying to get all the discs from the Left tower to the Right.
    2. Answer the questions posed above (is it solvable for 64 discs; how long would it take). Provide reasoning for your answers in the form of a logical argument or scratch work.
Thursday, November 1
Description
The Towers of Hanoi
Homework
  • Download the Towers of Hanoi Java class and complete it. When its done, it should work something like my solution (reminder, you can run it by typing java -jar TowersOfHanoi_solution.jar from a terminal window). Due Tuesday at the beginning of class. Extra credit: indent the instructions for each "level" of the puzzle that you're solving.
Friday, November 2
Description
Test Review
Homework
  • Read all of Chapter 5 (Pointers) in DSA.
  • Work on Towers of Hanoi Lab, due Tuesday at the start of class.