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()
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.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.
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:
According to the legend, if the monks are able to solve the puzzle, the universe will come to an end. So:
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:
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.