Assignment #13

Instructions

  1. Write a Java application that does the following.
    1. Implement a Postfix Calculator using a Stack by using the algorithm in the slides. See slides 41, 42, 43 titled "Infix to Postfix Algorithm" for the algorithm.
    2. Download the interface StackInterface.java and the class ArrayStack.java to your desktop.
      1. Save both files in the same folder (directory) as your LastnameFirstname13.java file.
      2. Do not make any changes to these files.
    3. Your program should use command-line input to read from a file. The file name is only argument on the command-line input, so args[0] is the file name. In you main method, read one line of data from the input file, calculate the result, then output to the screen. Repeat this until you reach the end of the file. Each line in the file will contain a infix expression.
    4. For an example of using the ArrayStack.java in a program, see example code ArrayStackDriver.java
    5. Use method equals() to compare two objects, such as String. Use operator == to compare primitive data objects, such as char. Do NOT use operator == to compare two objects. If you use == to compare objects, it only compares the addresses of the objects, and not the content of the objects, so the result is only true when the two objects are the same object. Otherwise, the result is false, even if the content of the object is the same. See this program for an example: Equals.java
    6. This assignment has been challenging for most students, so error checking is NOT required, except for:
      error checking for the commandline arguments to make sure one commandline argument is entered, and error checking for any file opening errors.
    7. Your output should be similar to the output below.
    8. Write your original comments every 3-5 lines of code.
    9. WARNING: Do NOT copy my code or my comments. Use my code as a guide to write your own code.
  2. Don't forget to add "JavaDoc" style comments above each method. See ICS 211 Java Coding Standard (Comments: Methods) for details.

Output

  1. Here is example output for input file: input13.txt
    Reading from file: input13.txt
    
    Infix expression   = (5)
    Postfix expression = 5
    
    Infix expression   = (1+1)
    Postfix expression = 11+
    
    Infix expression   = ((9/3)-2)
    Postfix expression = 93/2-
    
    Infix expression   = (9-(3/2))
    Postfix expression = 932/-
    
    Infix expression   = (1+(4-(9*(6/(5%7)))))
    Postfix expression = 149657%/*-+
    
    Infix expression   = ((1+4)-(((9*6)/5)%7))
    Postfix expression = 14+96*5/7%-
    
    Infix expression   = (((1+(4-9))*6)/(5%7))
    Postfix expression = 149-+6*57%/