java project and need the explanation and answer to help me learn.
I will post the PDF file for the details, and the price for the question will be discussed after, feel free to ask me any questions.
Requirements: meet all the requirements
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715341/16Project 3: Tower of HanoiDue Tuesday by 11:59pm Points 100 Submitting an external toolIt is an Honor Code violation to resubmit prior work from an earlier semester in thiscourse.It is an Honor Code violation to submit work authored by someone else as your own.You must include the following Virginia Tech Honor Code pledge at the very top of eachJava file you write (separate from the class Javadoc comment). Include your name andPID as shown, to serve as your signature:// Virginia Tech Honor Code Pledge://f// As a Hokie, I will conduct myself with honor and integrity at all times.// I will not lie, cheat, or steal, nor will I accept the actions of those who do.// — Your name (pid)Project 3 Tower of HanoiThe project will be graded on how well it executes. Project 3 Introduction Refer to your course materials, the Recursion Module(https://canvas.vt.edu/courses/165395/modules/355783) , and the following example videos tofamiliarize yourself with the famous Tower of Hanoi puzzle.This is a funny but informative video of a young person solving the puzzle blindfolded. Howdoes he know which disk to move when?? (Hint: recursion!)https://www.youtube.com/watch?v=gctRbzepm6c&spfreload=10Tower of Hanoi (https://www.youtube.com/watch?v=gctRbzepm6c&spfreload=10)
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715342/16(https://www.youtube.com/watch?v=gctRbzepm6c&spfreload=10)See below a more detailed video that includes a description in python. (You may want to skip tothe 8min0sec mark. In the first eight minutes, they explain the basics of the puzzle, which youalready know, and talk about a very cool way to intuit the solution using binary counting. By allmeans watch the whole video, especially if you’re into math!)https://youtu.be/2SUvWfNJSsM?t=480Binary, Hanoi and Sierpinski, part 1 (https://youtu.be/2SUvWfNJSsM?t=480)(https://youtu.be/2SUvWfNJSsM?t=480)In this project, your goal is to implement your own LinkedStack and solve the classic Tower ofHanoi problem using recursion. Using the algorithm as described in your course materials(within the Recursion Module Section 3 (https://canvas.vt.edu/courses/165395/pages/tower-of-hanoi) ), you will solve a puzzle, step by step, and display your moves in a Window. You’ll startthe puzzle with the program display looking something like this…and end it looking something similar to:
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715343/16 The design of this project separates the front-end and the back-end. The back-end extendsObservable and the front-end extends Observer. This design allows for separation ofresponsibility for the front and back ends which increases cohesion and reduces coupling.When there is a change in the observable back-end, the front-end observer is notified and canupdate the display accordingly.PrerequisitesSkills from project 1 such as unit testing, webCAT submission, use of CS2GraphWindowLib andCS2DataStructuresLibUsing a data structureCreating and manipulating linked chainsUnderstanding of stackConcepts behind building a data structure with a linked chainExpected Outcome
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715344/16 Project 3 Class Overview UML
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715345/16 Note: DISK_HEIGHT should be a constant field in PuzzleWindow and pop(), peek() andgetData() should have a return Type of T. Project 3 Steps Breakdown Implementation TipsThere are several classes that throw Runtime exceptions. Because these are Runtimeexceptions and not checked exceptions, a throws clause is not necessary. However, it isrecommended that conditions that cause the Runtime exceptions be listed in the class’sJavaDocs with @precondition tags.Create your project, Tower Of Hanoi, and set up your build path as you have in your previousprojects. For your import statements, only import the classes you need; you do not want Nodeor LinkedStack from CS2DataStructuresLib because you will be implementing those yourself.Notice in the UML diagram that the package name we are requiring you to use istowerofhanoi.Don’t forget to test as you go! We walk through the classes in the order that they rely on oneanother. Make sure each class is working properly before you move on to the next, or trackingdown your bugs will be much harder.Disk extends Shape implements Comparable
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715346/16once that class is written (in the meantime hardcode it or create a local constant). We’llmove these disks after they’re built. After calling super, set the disk’s background color toa random new Color. To randomly generate a color, we will use the TestableRandom classto generate random numbers. Import student.TestableRandom to use this class. Then wewill call the Color constructor with three random integers ranging from 0 to 255 (You willneed to: import java.awt.Color; to access Color class.)).compareTo(Disk otherDisk)For use in determining relative size of disks, our Disks are comparable to other disks. IfotherDisk is null, be sure to throw an IllegalArgumentException. Otherwise, compare widthsand return a negative number if this Disk is smaller than the disk parameter, a positivenumber for the opposite, and a zero if their widths are equal.toString()Return the width of this Disk as a string. Use its getWidth() method. For example, callingtoString()on a disk of width 10, disk1.toString(), should return “10”.equals(Object obj)Two disks are equal if they have the same width. See your course material and notes formore information on how to implement an equals method.LinkedStack implements StackInterfaceWrite a LinkedStack
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715347/16In the LinkedStack class, implement your own inner private Node class at the bottom of theclass. These Nodes should be singly linked. To make your logic easier, we recommendmaking a constructor which sets both its data and its nextNode fields immediately uponcreation. We leave the implementation largely up to you, since you have used a Nodeclass before (remember project 2, and your course materials). Be sure your project isusing your Node implementation and not the one from CS2DataStructuresLib. Suggested constructors for Node that correspond with this UML diagram and simplifytesting(tip added as of10/12/21): public Node(T entry, Node
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715348/16The example above [lastPush, secondPush, firstPush] depicts both a comma and aspace after each entry except for the last. Keep this in mind when implementing and testing your toString, This is generally theapproach we use throughout the course. For a given data structure, the toString( )returns a String representation of the data structure, where the elements are enclosed insquare brackets [ ] and are separated by a comma followed by a space. push(T anEntry)Push will “push” a new entry on the top of the stack. Place anEntry in a new Node, andset its nextNode to be your head field. This puts anEntry in front of your topNode. Finally,update topNode to be the new Node, and increment your size.peek()Peek exists to show what’s on the top of the stack, without modifying the stack in anyway. If the stack is empty, this method throws an EmptyStackException. Otherwise, returnyour topNode’s data. You’ll need to import java.util.EmptyStackException.pop()Pop will throw an EmptyStackException if called on an empty stack. Usejava.util.EmptyStackException. Otherwise, your job here is to take away the Node from thetop of the stack, and return its data. Store your topNode data field in a local variable. Setthe topNode to be the topNode’s next node, effectively losing the original top Node.Luckily, you already saved it as a local variable. Decrement your size, and return theoriginal top Node’s data.enumerator PositionThere are always three poles in the Towers of Hanoi puzzle, and so each Tower is associatedwith one of three positions: LEFT, MIDDLE, or RIGHT. Make a new Enum much like you wouldmake a new Class, go to File > New > Enum. Name it Position, and click Finish. Inside ourPosition enum file, you’ll see an empty code block. Inside, separated by commas, name yourpositions. They are…LEFT, MIDDLE, RIGHT, DEFAULT;… and will be used to determine the Tower position. The constructor in this Enum is notneeded.
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/16715349/16 Tower extends LinkedStack
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153410/16Your HanoiSolver represents a Tower of Hanoi puzzle. These puzzles vary in regard to howmany disks are used, so the constructor requires this as a parameter. There are always threetowers, so you will have three private Tower fields named left, middle, and right. You alsoextend Observable (by import java.util.Observable;), so that the PuzzleWindow may observeHanoiSolver to update the display that animates the Disks. Because Observable is deprecatedyou will notice it is show with strikethrough in eclipse. You can dismiss this as we use thisstraightforward interface for introductory experience.HanoiSolver(int numDisks)Every Tower of Hanoi puzzle requires the number of disks to be specified. StorenumDisks in a field, and initialize your three Tower fields to be new Towers, with thecorresponding Position.LEFT,Position.MIDDLE, or Position.RIGHT provided as parameters.Leave them empty for now. The front-end will fill them in later.disks()Return the number of disks, numDisks.getTower(Position pos)Depending on the position requested, return either left, middle, or right. The enumeratedtype makes it straightforward to use a switch statement here.Note that there is still the fourth enum type default. This is for testing purposes so that youhave a way to test the default case in your switch statement. In the default case, youshould return the middle tower.toString()Return left , middle, and right, as strings (use toString()), appended to each other. Forexample: if the left, middle, and right tower each have a single disk with width of 10, 20,and 30 respectively, the output of toString() is “[10][20][30]”. To test toString() you willneed to instantiate a HanoiSolver object and push disks onto its towers.move(Tower source, Tower destination)
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153411/16This method executes the specified move. Pop the Disk from the “source” Tower, andpush it onto the “destination” Tower. Any error checking and handling will be done by theTower class, such as IllegalStateException or NullPointerException. Now we need to thenindicate that something has changed about this class with a call to setChanged(), then tellany observers that it’s time to update with a call to notifyObservers(destination.position()).The destination tower’s position is provided, to communicate with the front-end as towhich Tower needs to be updated.solveTowers(int currentDisks, Tower startPole, Tower tempPole, Tower endPole)Implement your recursive solveTowers() method with help from your course materials.Start with the base case where there is only one disk left to move. Otherwise, yourecursively solve smaller sub-problems by calling solveTowers() with slightly differentparameters, invoking the move() method when it is necessary for a disk to be moved.solve()Your solve() method will be public. It makes the initial call to the recursive solveTowers()method. It provides the solveTowers() method the correct parameters, with left being thestart, middle being the temp, and right being the end.PuzzleWindow implements ObserverOur PuzzleWindow creates the Window in which we view the puzzle, and observes HanoiSolvergiven to it by the main method present in ProjectRunner (refer the complete UML diagram givenin the beginning) for updates on when to animate the Window. Because this class is an Observer(by import java.util.Observer;), it requires the update() method. Leave it empty for now. Thisfront-end class should have one HanoiSolver field named game, and three Shape fieldsindicating the left, middle and right towers on the front-end. How you use and name yourconstants is up to you. We grade for use of constants but since the ones in this method areprivate WebCAT will not be checking for specific usage. Because Observer is deprecated youwill notice it is show with strikethrough in eclipse. You can dismiss this as we use thisstraightforward interface for introductory experience.
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153412/16methods using ThreadsCopy and paste the two methods below into this PuzzleWindow. They deal with making aThread, which you don’t have to learn (yet!). We will use the sleep() method to pausebetween Disk movements. Without a pause, we wouldn’t be able to see the algorithm inaction. The clickedSolve(Button button) method supports your Solve button. The newThread is needed for clickedSolve() so that when it calls your game’s solve method, thedisplay is updated when the back-end changes. Try to understand how they work, andread a little about Threads online.private void sleep() { try { Thread.sleep(500); } catch (Exception e) { }}public void clickedSolve(Button button) { button.disable(); new Thread() { public void run() { game.solve(); } }.start();}moveDisk(Position position)This method updates the front-end, after the back-end has been changed. We only needthe position parameter so we can peek at the Disk that was just moved to get neededinformation for the display. The back-end already moved the disks between the Towers.Make a local Disk variable named currentDisk and a local Shape variable currentPole forstoring theDisk and pole associated with the move. Use position as a parameter togetTower() to get the current disk.
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153413/16Hint, to invoke getTower() from within moveDisk(Position position) please recall thefollowing:1) The getTower() method was implemented within HanoiSolver. 2) PuzzleWindow should include a field of type HanoiSolver (see UML for furtherdetail).Then, determine which Shape field corresponds to this position. If the Position is LEFT,set your local variable to be left, and so on.The moveTo() method that Disk inherits from Shape will graphically relocate the disk in thedisplay. Use the getX(), getY(), getWidth(), and getHeight() methods for the disk andpole to determine the new X and Y coordinates to which the disk will move. You will alsoneed the size() of the tower to know how many disks are underneath the current one, toadjust its Y position appropriately. If you want to add a gap between disks or a height fromthe base of the pole, you can use the final attributes DISK_GAP and DISK_HEIGHTrespectively in your calculations of the new y. The following diagram may help you withcoordinates:PuzzleWindow(HanoiSolver game)Note: You do not need to write unit tests for the PuzzleWindow class.Store the game parameter in a field, and call game’s addObserver(this) method. Provide“this” (not a string) as its parameter to indicate that this class is observing it for updates.
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153414/16Declare a new Window as a class field. Give it the title “Tower of Hanoi”.Now we’re going to initialize your Shape fields that represent the towers. They should bevery tall and narrow rectangles, somewhat reasonably spaced in the window, with the leftone being the farthest left, and so on. The Color and everything else is up to you. Onceyou see them on the display, play with the parameters. They should not affect yourprogram’s performance or test compatibility.In a for loop, based on the game’s number of disks, generate the disks from largest tosmallest. Make a new Disk with its width based on the for loop’s index. Make the diskwidth a multiple of some number between 5 and 15, depending on your aestheticpreference. Next, add the Disk to the Window. Push each Disk onto the game’s leftTower, then call moveDisk(Position.LEFT) inside the loop. This will update the disk’s x,ylocation to the correct spot on the Window.After the loop, add the previously created left, middle, and right Shape fields to the Window.We add them after the disks so that they appear underneath the disks. If you want tomanipulate the ordering of aShape, you can call its bringToFront() or sendToBack()methods.For appearances’ sake, you can also add a low and wide rectangle centered underneatheach tower. This gives the appearance of the base, and looks nice. This is not required.Now we’ll deal with your button. Declare a new Button named “solve” that says “Solve”,add it to the NORTH side of the Window, and tell it to onClick(this, “clickedSolve”).update(Observable o, Object arg)Our update method is called automatically when the game’s move method callsnotifyObservers. InHanoiSolver, we passed notifyObservers() a Position as a parameter.That Position will passed as our arg parameter here.To start, check if arg.getClass() equals Position.class. If true, cast your arg to be aPosition. Call the previously created moveDisk method with your position, then callsleep().ProjectRunnerNote: You do not need unit tests for the ProjectRunner class.As in previous projects, this last class is where your main method lives.main(String[] args)The last method! Here, we make a new PuzzleWindow, and pass it a new HanoiSolver,which we pass the number of disks to use. To determine how many disks to use, declarea local variable named disks that is six by default. If the String array args length isexactly one, set your disks integer to be the Integer parsed from the args[0] location
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153415/16(disks = Integer.parseInt(args[0])). This allows you to change this program’s RunConfiguration… > Arguments to any number you like, but only if there’s one argument.Optional Features:These ideas are purely optional, for if you want to do more. Make sure that your tweaks don’tbreak the original functionality, or you may resubmit and find your grade went down! To avoidthis, get a 100% before trying these options.Dynamically set pole and base dimensionsYou might want to only make the bases and poles as large as you need to hold as many disksas the game is currently running with. The change is slightly prettier, with a little math involved.Provide a step-by-step buttonWhenever clicked, only move one step through the solve algorithm. Make sure that the solvebutton still works after the user has pressed the step button several times.Speed optionsTo accelerate longer puzzles, adjust your sleep time based on the number of disks. Modify theprovidedsleep() method to provide this behind-the-scenes tweak.Allow user interaction with disksTo let users solve the puzzle themselves, you can allow users to drag and drop their shapes.Provide the shapes with an onClick method, such that users can click a Disk, then click a Poleto specify a move. Make sure your step-by-step and solve buttons still work if the user performsthese interactions! You also might want to make your disks bigger than in the examples to makethem easier to click on. SubmissionWeb-CAT Grading Rubric 50 pts WebCAT50 pts Execution, Style and Documentation
3/15/23, 6:56 PMProject 3: Tower of Hanoihttps://canvas.vt.edu/courses/165395/assignments/167153416/16Upload Your File(s)Upload Your File(s)Submission EnergyFor: CS 2114 (13315/22750 F 2:30 PM – 5:00 PM) Project 3: Tower of Hanoi: Project 3: Tower of HanoiUpload Submission (/Web-CAT/WebObjects/Web-CAT.woa/wo/65.0.0.0.29.1.9.0.1.1.1.0.0.1.9.1.1.1)
We are a professional custom writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework.
Yes. We have posted over our previous orders to display our experience. Since we have done this question before, we can also do it for you. To make sure we do it perfectly, please fill our Order Form. Filling the order form correctly will assist our team in referencing, specifications and future communication.
1. Click on the “Place order tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
2. Fill in your paper’s requirements in the "PAPER INFORMATION" section and click “PRICE CALCULATION” at the bottom to calculate your order price.
3. Fill in your paper’s academic level, deadline and the required number of pages from the drop-down menus.
4. Click “FINAL STEP” to enter your registration details and get an account with us for record keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
5. From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.
Need this assignment or any other paper?
Click here and claim 25% off
Discount code SAVE25