Java Question Stack Implementation

timer Asked: Nov 8th, 2016

Question description

This is a three part project:

  1. Implement the stack interface that I have attached as both a dynamic size array and as a linked list.
  2. Implement functions to convert one type of notation to any other type (eg infix to prefix).
  3. Implement an expression evaluation function.

You should write a driver program called '' which prompts the user for the type of notation that he would like to enter, followed by the notation he would like to to convert to.


Possible Conversions

There are six possible user requests:

  1. infix to postfix
  2. infix to prefix
  3. prefix to infix
  4. prefix to postfix
  5. postfix to infix
  6. postfix to prefix

Note: Implement all of these as separate functions. Don't use intermediate conversions.


All variables should be single chars A-Z or a-z. If anything else is processed, then the expression is illegal and you should report it as such.


The only operators that you should process: +,-,*,/,^

Any other operator found should cause an illegal expression to be reported.

Parens and Brackets

You are expected to process infix notations that have (),[],{} groupings. If you encounter any kind of missmatch, then you should report the illegal expression.


What type of expression would you like to enter:

1) Infix

2) Postfix

3) Prefix

0) Quit

Enter expression:

What would you like to do:

1) Convert to infix

2) Convert to prefix

3) Convert to postfix

4) Evaluate Expression

5) Return to Main Menue

0) Quit

Test Cases

As with all our projects, you are expected to generate your own test cases. Think about all the possible edge cases. Consider mismatched parens or brackets, invalid operators and invalid variable names.

Follow the style sheet provided below !!

/** * An interface for the Stack ADT. * * @author Gilberto Perez * @version 1.0 */ ///////////////////////////////////////////////////////////////////// public interface Stack { // Core stack functions boolean push(T newEntry); // Attempt to add a new entry. T pop(); // Remove the top entry T peek(); // Returna reference to the top entry, but do not remove. // A few extra methods int getSize(); boolean isEmpty(); void clear(); // Remove all entries from stack String toString(); } /////////////////////////////////////////////////////////////////////
Dr Barry Soroka Cal Poly Pomona Style Sheet for Java Version of 121005 1. Classes should be enclosed between rows of slashes: ///////////////////////////////////////////////////////////////////// A row of slashes may be used in no other way. See the Examples of Java Style on my home page. 2. Methods should be enclosed between rows of dashes: //------------------------------------------------------------------- Thus, a row of hyphens will separate the instance variables from the first method in a class. Similarly, a row of hyphens should precede the first method in a class if there are no class or instance variables. A row of hyphens may be used in no other way. See the Examples of Java Style on my home page. 3. Class names have all words capitalized. For example: Complex, RationalNumber. 4. Variables, methods, and instances have names in which all words are capitalized except the first word. For example: sum, dateLastModified, nUpperCase. 5. Constants are written in all capital letters. Underscores may be used to separate words. For example, MAX_SIZE, E, PI. Underscores are only permitted in constants. 6. Within a class, the order should be: variables, constructors, methods. 7. In general, instance variables should be private. 8. Instance variables should be initialized in constructors, not in their declarations. 9. final variables should be initialized in their declarations. 10. Do not rely on Java’s default initialization of variables. 11. Always label instance variables and methods as public or private etc. 12. Here is an example of the required indentation scheme: public static void main ( String [] args ) { if (a == b) { System.out.println("They\'re equal!"); } } 13. If only a single statement follows an if or else, then the braces may be omitted: if (cond1) System.out.println(1); else if (cond2) System.out.println(2); else System.out.println(3); 14. Avoid nested if statements — they can become very hard to understand and debug. Multiway branches — if ... else if ... else if ... else are an exception. C:\Users\cloudconvert\server\files\116\313\6\o12tUcE5zyVuvjpRODKi\20161108054924java_style _sheet.doc Dr Barry Soroka Cal Poly Pomona 15. Indent each level by three spaces. Do not indent using the TAB key. The notation “IND” means that your indentation is incorrect. 16. Names of classes, methods and instances should reflect the purpose of said classes, methods, and instances. “BVN” is the notation for “Bad Variable Name.” 17. Include your name in a comment near the top of each code file. The grading notation “NNIC” means “No Name In Code.” 18. Hardcopy of Java code, data, and output should be printed using a fixed-width font. “UFWF” is the notation for “Use Fixed Width Font.” 19. When printing, be sure that single lines of code are not split across several output lines. Avoid wraparound (“WA”). 20. If a statement occupies multiple lines, then lines after the first line should be indented at least one level more than the first line. C:\Users\cloudconvert\server\files\116\313\6\o12tUcE5zyVuvjpRODKi\20161108054924java_style _sheet.doc

Tutor Answer

(Top Tutor) Studypool Tutor
School: Cornell University
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors