Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Develop a new stand-alone generic class, called StackYourname, to implement, among others, key stack operations [push(e), pop(), peek(), size(), isEmpty()]we discussed in the

Part 1: Develop a new stand-alone generic class, called StackYourname, to implement, among others, key stack operations [push(e), pop(), peek(), size(), isEmpty()]we discussed in the class. Note that our LinkedList class does not use variable size, but you can use variable size in this class StackYourname. Again, class Stack needs to be defined as generic stack with type so that we can create stack objects that can hold data of different types, such as integer stack, string stack, char stack, double stack, etc. Furthermore, define class Node as part of class Stack, similar to class LinkedList in the previous assignment. StackYourname Class must have these methods - methodname(argument): return type - isEmpty(): Boolean Returns true if this stack is empty - size(): int Returns the number of elements in this stack - peek(): E Returns the top element in this stack - pop(): E Returns and removes the top element in this stack - push(E element): E Adds a new element to the top of this stack - search(E element): int Returns the position of the specified element in this stack - toString(): String Returns the String with all elements in current stack

Part 2: Next, develop a simple test program called TestStackYourname, similar to that you developed in the previous assignment, to test each stack operation listed above and defined in your class Stack. Use integer type stack for the test program. Organize the outputs of this test program similar to that of test linked-list, where you need to show the stack content before and after calling a stack operation. Use proper labels. Please DO NOT hard-code test data. Make sure to allow the user to enter the stack content using interactive menu (embedded inside the sentinel loop): -----MAIN MENU----- 0 - Exit Program 1 - Push 2 - Pop 3 Peek (Top) 4 - Size 5 Is Empty? 6 - Print Stack Again, you cannot change method names, return type and parameter types. To evaluate your Classs methods, the instructor will use another Test Program and will use your methods.

Part 3: Using class StackYourname above, implement another short and simple program, call it TestPalindromeYourname, which prompts the user to enter a string value of any length. Using class StackYourname, the TestPalindrome program creates one stack object and uses the object to check whether the entered input string is a palindrome or not. The program displays both the input string and the judgment statement (Palindrome or Not Palindrome). This program is case insensitive. Also, it ignores whitespaces. Enter a string: Race car Input String: Race car Judgment: Palindrome Enter a string: CS5040 Input String: CS5040 Judgment: Not Palindrome You can use a sentinel loop to run the program again and again. But it is not mandatory, it is good even if your program runs only one time.

Part 4: Using class StackYourname above, implement another short and simple program, call it PostfixEvalYourname, which prompts the user to enter a string value of postfix expression. Using class StackYourname, the program should evaluate the postfix expression and get the correct calculated result. The program displays both the input Assumption: Input postfix string doesnt have whitespaces. All input number is one-digit number. (positive digit 0 to 9) Operator ^ + - * / can be used. If postfix input is not calculatable, show the result Enter a string: 562^2-* Result value: 170 Enter a string: 562^2- Result value: The input Postfix expression is not valid.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago