Advertisement
noviceJ

loopThatSwitch.java

Sep 3rd, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class loopThatSwitch
  3. {
  4.     public static void main(String [] args)
  5.     {
  6.         for (int i = 0; i < 1; i++)
  7.         {
  8.         String options = JOptionPane.showInputDialog("[A] Add\n[B] Subtract\n[C] Multiply\n[exit] To exit program");
  9.  
  10.        
  11.        
  12.        
  13.         switch(options) {
  14.            
  15.             case "exit":
  16.             System.exit(0);
  17.             break;
  18.             case "A":
  19.             String addx = JOptionPane.showInputDialog("Add");
  20.             int add1 = Integer.parseInt(addx);
  21.             String addy = JOptionPane.showInputDialog("Add");
  22.             int add2 = Integer.parseInt(addy);
  23.             int result1 = add1 + add2;
  24.             JOptionPane.showMessageDialog(null, addx +" + " + addy + " = " + result1);
  25.             break;
  26.            
  27.             case "B":
  28.             String minusx = JOptionPane.showInputDialog("Subtract");
  29.             int sub1 = Integer.parseInt(minusx);
  30.             String minusy = JOptionPane.showInputDialog("Subtract");
  31.             int sub2 = Integer.parseInt(minusy);
  32.             int result2 = sub1 - sub2;
  33.             JOptionPane.showMessageDialog(null, minusx + " - " + minusy + " = " + result2);
  34.             break;
  35.            
  36.             case "C":
  37.             String timesx = JOptionPane.showInputDialog("Multiply");
  38.             int  mul1 = Integer.parseInt(timesx);
  39.             String timesy = JOptionPane.showInputDialog("Multiply");
  40.             int mul2 = Integer.parseInt(timesy);
  41.             int result3 = mul1 * mul2;
  42.             JOptionPane.showMessageDialog(null, timesx + " x " + timesy + " = " + result3);
  43.             break;
  44.            
  45.             default:
  46.             JOptionPane.showMessageDialog(null, "Please select operations", "Error", JOptionPane.ERROR_MESSAGE);
  47.             break;
  48.         }
  49.            
  50.         }
  51.        
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement