Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Towers of Hanoi (15 points) Given: n disks, all of different sizes the size of the ith disk is .3 pegs - A, B, C
Towers of Hanoi (15 points) Given: n disks, all of different sizes the size of the ith disk is .3 pegs - A, B, C the number of pegs might change in a future version of the game Inally, all the disks are stacked on peg A Requirement: Never place a larger disk on top of a smaller disk (disk 5 is larger than disk 4, etc.) Objective: Move the disks from peg A to peg C Input: n, the number of disks initially stacked on peg A; you should get n from the command line, as a command line argument; assume n 10 Output: Commands describing how the player should move the pegs Example If 3 is input then the output should be Move Peg Configuration in I from A to C 2 from A to B I from C to B from A toC I from B to A 2 from B to C I from A to C 3 2 1 3 2 1 Strategy: If there are n disks on peg A and we need to move them to peg C then we'll use peg B as a utility peg Move the top n-1 disks from A to B Move the nh disk from A to C Move the n-1 disks from B to C, using peg A as a utility OR If we must move n disks on the source peg to the dest pegusing a utility peg Move the top n-1 disks from source to utility Move the nh disk from source to dest Move the n-1 disks from utility to dest, using peg source as a utility Be sure to choose appropriate classes - it should require minimal changes if we desire to modify the problem to include any number of pegs (you should provide a flexible, extensible solution) or modify our strategy. Note your class cohesion and degree of coupling between classes (maximize cohesion, minimize coupling) You are expected to think about and correctly identify the objects in this exercise. The reasons I assigned this exercise are for you: - To get more practice programming in Java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started