//import packages needed
import javax.swing.*;
import java.awt.*;
public class Math {
public static void main (String args[]) {
//decalre variables
double message,S,A,M,D, choice = 4;
char character;
int num, answer;
//Shows a dialog for the user to input their choice
choice = Double.parseDouble(JOptionPane.showInputDialog("A (for subtraction)" + "\nS (for Subtraction)" + "\nM (for multiplication)" +
"\nD (for division)"));
//Case statement to determine what is selected first
JOptionPane.showInputDialog("Please enter a number: ");
while (character != character)
{
JOptionPane.showInputDialog("Please enter a number: ");
}
switch (character)
{
case 1:
if (choice == A)
{
answer = num + num;
}
break;
case 2:
if (character == S)
{
answer = num - num;
}
break;
case 3:
if (character == M)
{
answer = num * num;
}
break;
case 4:
if(character == D)
{
answer = num / num;
}
break;
default:
JOptionPane.showMessageDialog(null, "WARNING","You have not entered the value correctly", JOptionPane.WARNING_MESSAGE);
}
}
}
I hope someone can at least help me figure out what is wrong with this. I have been looking for a few hours now and i can't figure what i am doing wrong. All i know is i may need to assign the choices A, S, M, D but to what exactly. I'd much appreciated if you can point out what is needed and if i am doing it correctly. Yes i know i have to place an output message at the end but i'm trying to make the case better so it wuld at least compile. Hope i get some help. No, i'm not asking to fully complete my homework all i am doing here is asking for some help. I normally learn visually so it makes sense if my code looks less of a programmer typed.

New Topic/Question
Reply



MultiQuote







|