Help!
My boyfriend has been trying to figure out this program for his java class for over a week..to no avail. The teacher won't help him and he's at his wits end. I think it's supposed to be a calculator program. He says he's having trouble getting the operator character to read into the program. Can any of you figure this out? Here's what he has for his program so far:
My boyfriend has been trying to figure out this program for his java class for over a week..to no avail. The teacher won't help him and he's at his wits end. I think it's supposed to be a calculator program. He says he's having trouble getting the operator character to read into the program. Can any of you figure this out? Here's what he has for his program so far:
import java.util.StringTokenizer;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import java.io.*;
public class Calculator
{
public static void main(String [] arg) throws IOException
{
BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer;
int results, results2, results3, results4, num1, num2/*, operator*/, test;
String operator;//, num1, num2;
String pane1, pane2;
pane1 = JOptionPane.showInputDialog("The purpose of this program is to mimic a calculator."
+ "\n\n\nPlease enter the data in this format | 1 + 2 | .");
tokenizer = new StringTokenizer (pane1);
num1 = Integer.parseInt(tokenizer.nextToken());
operator = tokenizer.nextToken();
num2 = Integer.parseInt(tokenizer.nextToken());
test = (char) '+';
results = (num1 + num2);
results2 = (num1 - num2);
results3 = (num1 * num2);
results4 = (num1 / num2);
if (operator = test )
JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
/*
else if (test == '-')
JOptionPane.showMessageDialog(null, "Your results are " + results2 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
else if (test == '*')
JOptionPane.showMessageDialog(null, "Your results are " + results3 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
else if (test == '/')
JOptionPane.showMessageDialog(null, "Your results are " + results4 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
switch (operator)
{
case '+' : JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
}
*/
System.exit(0);
}
}
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import java.io.*;
public class Calculator
{
public static void main(String [] arg) throws IOException
{
BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer;
int results, results2, results3, results4, num1, num2/*, operator*/, test;
String operator;//, num1, num2;
String pane1, pane2;
pane1 = JOptionPane.showInputDialog("The purpose of this program is to mimic a calculator."
+ "\n\n\nPlease enter the data in this format | 1 + 2 | .");
tokenizer = new StringTokenizer (pane1);
num1 = Integer.parseInt(tokenizer.nextToken());
operator = tokenizer.nextToken();
num2 = Integer.parseInt(tokenizer.nextToken());
test = (char) '+';
results = (num1 + num2);
results2 = (num1 - num2);
results3 = (num1 * num2);
results4 = (num1 / num2);
if (operator = test )
JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
/*
else if (test == '-')
JOptionPane.showMessageDialog(null, "Your results are " + results2 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
else if (test == '*')
JOptionPane.showMessageDialog(null, "Your results are " + results3 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
else if (test == '/')
JOptionPane.showMessageDialog(null, "Your results are " + results4 + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
switch (operator)
{
case '+' : JOptionPane.showMessageDialog(null, "Your results are " + results + ".", "Your results are...", JOptionPane.INFORMATION_MESSAGE);
}
*/
System.exit(0);
}
}
Comment