[code]
import javax.swing.JOptionPane;
import java.util.*;
public class PolishNotationCalculator
{
public static void main (String [] args)
{
do
{
try
{
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog(null, "You must enter a number for the operand", "Input Error",
JOptionPane.ERROR_MESSAGE);
}
catch (NoSuchElementException mistake)
{
JOptionPane.showMessageDialog(null, "You must enter an equation to be evaluated", "Input Error",
JOptionPane.ERROR_MESSAGE);
}
PolishNotationCalculator calculator = new PolishNotationCalculator (taxpayer.getTaxpayer());
int result = calculator.evaluate();
System.out.println(result);
}
while (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Do you want to enter another?", "Enter Scores",
JOptionPane.YES_NO_OPTION));
}
String getEquation = JOptionPane.showInputDialog(null, "Please enter an equation to be evaluated using Polish
Notation \n" + "i.e enter +, -, /, *, first and then two numbers \n"+ "example + 3 4 for 3 + 4", "Polish
Calculator",JOptionPane.QUESTION_MESSAGE);
private String [] taxpayer;
private int index;
public PolishNotationCalculator (String [] taxpayer)
{
setTaxpayer(taxpayer);
index = 0;
}
// get methods
public String [] getTaxpayer ()
{
StringTokenizer tok = new StringTokenizer(getEquation);
int length = getEquation.length();
String [] taxpayer = new String [length];
while (tok.hasMoreTokens())
{
int x = 0;
do
{
taxpayer[x] = tok.nextToken();
++x;
}
while (x < length);
return taxpayer;
}
//set methods
public void setTaxpayer ( String [] taxpayer)
{
taxpayer = taxpayer;
}
public int evaluate ()
{
int retval = 0;
if ("+".equals(taxpayer[index]))
{
++index;
int op1 = evaluate();
++index;
int op2 = evaluate();
retval = op1 + op2;
}
else if ("-".equals(taxpayer[index]))
{
++index;
int op1 = evaluate();
++index;
int op2 = evaluate();
retval = op1 - op2;
}
else if ("x".equals(taxpayer[index]))
{
++index;
int op1 = evaluate();
++index;
int op2 = evaluate();
retval = op1 * op2;
}
else if ("/".equals(taxpayer[index]))
{
++index;
int op1 = evaluate();
++index;
int op2 = evaluate();
retval = op1 / op2;
}
else
{
retval = Integer.parseInt(taxpayer[index]);
}
return retval;
}
}
[/code}
Why am I getting these errors:
/tmp/6417/PolishNotationCalculator.java:65: illegal start of expression
public void setTaxpayer ( String [] taxpayer)
^
I promise you once I finished with this class I won;t be brothering any of you again. I am so done with
Java.
Please help.
Bradley