You just reminded me why I wanna quit my IT course last year.Originally posted by lional88:eh i done a simple prog for java for a "calculator" but not sure which part i made mistake, nid help =(
Source code:
import javax.swing.JOptionPane;
public class SuperCalculator
{
public static void main(String[] args)
{
String InputString = JOptionPane.showInputDialog(null,
"What is your command my leader ?\n"
+"+ - Add two numbers for me\n"
+"- Minus two numbers for me (num1 – num2)\n"
+"/ - Divide two numbers for me (num1 / num2)\n"
+"* - Multiply two numbers for me\n"
+"D - Display the 5 previous commands and answers\n"
+"P - Play the super duper text game\n"
+"Q - Quit and exit the program.\n",
"Super Calculator Software",JOptionPane.QUESTION_MESSAGE);
if (InputString.charAt(0) == '+') {
String dataString1 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data1 = Double.parseDouble(dataString1);
String dataString2 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data2 = Double.parseDouble(dataString2);
double sum =data1 +data2;
JOptionPane.showMessageDialog(null,"The sum is "+sum ,"Super Calculator Software", JOptionPane.INFORMATION_MESSAGE);
else if (InputString.charAt(0) == '-') {
String dataString1 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data1 = Double.parseDouble(dataString1);
String dataString2 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data2 = Double.parseDouble(dataString2);
double sum =data1 -data2;
JOptionPane.showMessageDialog(null,"The sum is "+sum ,"Super Calculator Software", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
Originally posted by lional88:
eh i done a simple prog for java for a "calculator" but not sure which part i made mistake, nid help =(
Source code:
import javax.swing.JOptionPane;
public class SuperCalculator
{
public static void main(String[] args)
{
String InputString = JOptionPane.showInputDialog(null,
"What is your command my leader ?\n"
+"+ - Add two numbers for me\n"
+"- Minus two numbers for me (num1 – num2)\n"
+"/ - Divide two numbers for me (num1 / num2)\n"
+"* - Multiply two numbers for me\n"
+"D - Display the 5 previous commands and answers\n"
+"P - Play the super duper text game\n"
+"Q - Quit and exit the program.\n",
"Super Calculator Software",JOptionPane.QUESTION_MESSAGE);
if (InputString.charAt(0) == '+') {
String dataString1 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data1 = Double.parseDouble(dataString1);
String dataString2 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data2 = Double.parseDouble(dataString2);
double sum =data1 +data2;
JOptionPane.showMessageDialog(null,"The sum is "+sum ,"Super Calculator Software", JOptionPane.INFORMATION_MESSAGE);
} <- add this brace
else if (InputString.charAt(0) == '-') {
String dataString1 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data1 = Double.parseDouble(dataString1);
String dataString2 = JOptionPane.showInputDialog(null,
"Enter an Integer value,\n"
+"The program exits if the input is 0","Super Calculator Software", JOptionPane.QUESTION_MESSAGE);
double data2 = Double.parseDouble(dataString2);
double sum =data1 -data2;
JOptionPane.showMessageDialog(null,"The sum is "+sum ,"Super Calculator Software", JOptionPane.INFORMATION_MESSAGE);
}
} <- remove this brace
}
}
thx!Originally posted by sohguanh: