1. In this project, you will design and implement a class called Towers, which is part of a program that lets a child play a game called Towers of Hanoi. The game consists of three pegs and a collection of rings that stack on the pegs. The rings are different sizes. The initial configuration for a five-ring game is shown here, with the first tower having rings from one inch (on the top) to five inches (on the bottom).
The rings are stacked in decreasing order of their size, and the second and third towers are initially empty. During the game, the child may transfer rings one at a time from the top of one peg to the top of another. The goal is to move all the rings from the first peg to the second peg. The difficulty is that the child may not place a ring on top of one with a smaller diameter. There is the one extra peg to hold rings temporarily, but the prohibition against a larger ring on a smaller ring applies to it as well as to the other two pegs. A solution for a three-ring game is shown at the top of the next page. The Towers class must keep track of the status of all three pegs. You might use an array of three pegs, where each peg is an object from the previous project. The Towers methods are specified here:
Also include a method so that a Towers object may be displayed easily.
Use the Towers object in a program that allows a child to play Towers of Hanoi. Make sure you don’t allow the child to make any illegal moves.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here