GUI Based Menu Calculator Using Swing Package
import javax.swing.JOptionPane;
class MenuCalc{
public static void main(String[]args) throws Exception{
String select = JOptionPane.showInputDialog( "Enter Number 1-5" +
"\n 1 == Addition " +
"\n 2 == Subtraction " +
"\n 3 == Multiplication " +
"\n 4 == Division " +
"\n 5 == Reminder ");
int Menu = Integer.parseInt(select);
String v1 = JOptionPane.showInputDialog( "Enter First Value ");
int value1 = Integer.parseInt(v1);
String v2 = JOptionPane.showInputDialog( "Enter Second Value ");
int value2 = Integer.parseInt(v2);
if(Menu == 1)
JOptionPane.showMessageDialog(null, value1 + value2);
if(Menu == 2)
JOptionPane.showMessageDialog(null, value1 - value2);
if(Menu == 3)
JOptionPane.showMessageDialog(null, value1 * value2);
if(Menu == 4)
JOptionPane.showMessageDialog(null, value1 / value2);
if(Menu == 5)
JOptionPane.showMessageDialog(null, value1 % value2);
if(!( Menu == 1 || Menu == 2 || Menu == 3 || Menu == 4 || Menu == 5))
JOptionPane.showMessageDialog(null, " Enter Valid Menu ");
}
}
No comments:
Post a Comment