Question: Help with this programming/java project. Thank you. Program 1. Implement a stack using an array. Make your stack size 5. Use lowercase stack for your

Help with this programming/java project. Thank you.

Program 1.

Implement a stack using an array. Make your stack size 5. Use lowercase stack for your class name, do not use Stack class defined in java.

stack()creates an empty stacks, stacks is new and empty.push(item)adds a new item to the stacks, stacks is modified.pop()removes and returns an item, stacks is modified.isEmpty()returns a boolean and tests for an empty stacks, stacks is not modified.size()returns the int size of the stacks, stacks is not modifiedprint() prints the stacks from front to rear, stacks is not modified.top() prints the front element, stacks is not modified.

Driver should print the results of the following

push(redShirt) push(greenShirt) push(yellowPants) push(purpleSock) push(pinkSocks) size() push(blueShirt) size() pop() pop() size() pop() top() pop() pop() size() isEmpty()

Program 2.

Your program uses call stack for methods.

For instance, if your program has a main method (all java programs have one!) and it calls a computeArea method, then the call stack will have main first pushed, then computeArea. When your program returns from computeArea, that call information is popped off the call stack. The remaining method call (in this case, main) tells the program where to return. You can think of calling top() or peek() to get the top element of the stack without popping it off the stack.

Running the program see the call stack as the having the following stack methods

push(main) push(computeArea) pop(computeArea) pop(main)

Another example, if your program contains a main method that calls computeBalance which in turn calls computeInterest, the stack would have main, computeBalance, computeInterest. Each would be popped off in turn when the method completes and returns.

Write a small program with 4 methods named method1, method2, method3 and method4. These methods only need to have print statements saying "In method1" and "Exiting method1". (Similar to the first program above) In main, start with a print statement "In main method" then call the various methods in various orders. End your main method with "Exiting main" print statement. Submit your callStackLastName.java and callStackDriverLastName.java with a comment explaining your output.

Program 3. Implement the Towers of Hanoi in java.

Print the number of moves given the number of disks you are playing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!