# Java代写 | ACO201 – Data Structures and Algorithms

ACO201 – Data Structures and Algorithms

1. Problem Description
In class, we went over postfix expressions and an approach for evaluating them using a Stack. The
Java code was likewise presented and is available in Canvas. You are to enhance this code and include
the several additional operations listed below. Your Java program will continue to prompt the user
for additional expressions until the user chooses to finish. Your solution should handle any exceptions
gracefully and report the error.
This program is to be done on your own, not part of a team.
• Add the following new binary operators:
• Modulus: e1 e2 %
• Power (e1 raised to the e2 power): e1 e2 ^
• Example Expressions:
17 5 % (Result: 2)
3 4 ^ (Result: 81)
• Add the following new unary operators:
• Unary minus: e ~
• Factorial: e !
• Example Expressions:
12 ~ (Result: -12)
5 ~ ~ ~ (Result: -5)
6 ! (Result: 720)
3 ! 4 * 5 3 % – 4 2 ~ / * (Result: -44)
• Add the following relational, Boolean and ternary operators:
• Relational Operators: e1 e2 >, e1 e2 <, e1 e2 =
• Boolean Operators: e1 e2 &, e1 e2 |
• Ternary Operator (if e1 is true, value is e2, otherwise e3): e1 e2 e3 ?
• Example Expressions:
5 3 > (Result: 1)
5 3 < (Result: 0)
5 5 = (Result: 1)
10 5 & (Result: 1) Anything non-0 is considered “true”
5 3 > 2 3 > | (Result: 1)
0 0 | (Result: 0)
5 3 < 2 5 = 1 7 < | | 10 20 ? (Result: 10)
1 2 ? (Result: Error)
2. Notes
• Do not create these classes in a package. For Eclipse, this means using the default package.
• Turn in only your Java files: PostfixTester.java and PostfixEvaluator.java.
• For Boolean values, use the same convention that the C language does: 0 is false, non-0 is true.
• In Java the ^ operator is exclusive-OR, NOT power, as we are using it here.