Advertisement
noviceJ

counter.java

Sep 3rd, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3.  
  4. public class counter
  5. {
  6.     public static void main(String [] args)
  7.     {
  8.         int counter = 1;
  9.        
  10.         do
  11.         {
  12.             String options = JOptionPane.showInputDialog("[A] Add\n[B] Subtract\n[C] Multiply\n[D] Divide\n[E] Maximum\n[F] Minimum\n[G] Square root\n[exit] To exit");
  13.             if(options.isEmpty())
  14.             {
  15.                 JOptionPane.showMessageDialog(null, "Nothing selected");
  16.             }
  17.             if (options.equalsIgnoreCase("a"))
  18.             {
  19.                 String addX = JOptionPane.showInputDialog("Enter first number to add");
  20.                 String addY = JOptionPane.showInputDialog("Enter second number to add");
  21.                 int addA = Integer.parseInt(addX);
  22.                 int addB = Integer.parseInt(addY);
  23.                 int result = addA + addB;
  24.                 JOptionPane.showMessageDialog(null, result);
  25.             }
  26.            
  27.             else if (options.equalsIgnoreCase("b"))
  28.             {
  29.                 String subX = JOptionPane.showInputDialog("Enter first number to subtract");
  30.                 String subY = JOptionPane.showInputDialog("Enter second number to subtract");
  31.                 int  subA = Integer.parseInt(subX);
  32.                 int  subB = Integer.parseInt(subY);
  33.                 int result = subA - subB;
  34.                 JOptionPane.showMessageDialog(null, result);
  35.             }
  36.             else if(options.equalsIgnoreCase("c"))
  37.             {
  38.                 String mulX = JOptionPane.showInputDialog("Enter first number to multiply");
  39.                 String mulY = JOptionPane.showInputDialog("Enter second number to multiply");
  40.                 int mulA = Integer.parseInt(mulX);
  41.                 int mulB = Integer.parseInt(mulY);
  42.                 int result = mulA * mulB;
  43.                
  44.                 JOptionPane.showMessageDialog(null, result);
  45.             }
  46.             else if (options.equalsIgnoreCase("Exit"))
  47.             {
  48.                 int result = JOptionPane.showConfirmDialog(null, "Do you want to exit the program?", "Exit", JOptionPane.YES_NO_OPTION);
  49.                 if (result == JOptionPane.YES_OPTION)
  50.                 {
  51.                     System.exit(0);
  52.                 }
  53.                
  54.             }
  55.            
  56.             else if (options.equalsIgnoreCase("D"))
  57.             {
  58.                 String divX = JOptionPane.showInputDialog("Enter number to divide");
  59.                 String divY = JOptionPane.showInputDialog("Enter number to divide first number");
  60.                 int divA = Integer.parseInt(divX);
  61.                 int divB = Integer.parseInt(divY);
  62.                 int result = (divA / divB);
  63.                 JOptionPane.showMessageDialog(null, result);
  64.             }
  65.             else if (options.equalsIgnoreCase("E"))
  66.             {
  67.                 String maxX = JOptionPane.showInputDialog("Enter number");
  68.                 String maxY = JOptionPane.showInputDialog("Enter another number");
  69.                 int maxA = Integer.parseInt(maxX);
  70.                 int maxB = Integer.parseInt(maxY);
  71.                 int result = Math.max(maxA, maxB);
  72.                
  73.                 JOptionPane.showMessageDialog(null, result);
  74.             }
  75.             else if (options.equalsIgnoreCase("F"))
  76.             {
  77.                 String minX = JOptionPane.showInputDialog("Enter number");
  78.                 String minY = JOptionPane.showInputDialog("Enter another number");
  79.                 int minA = Integer.parseInt(minX);
  80.                 int minB = Integer.parseInt(minY);
  81.                 int result = Math.min(minA, minB);
  82.                 JOptionPane.showMessageDialog(null, result);
  83.             }
  84.            
  85.             else if(options.equalsIgnoreCase("G"))
  86.             {
  87.                 String sqrtX = JOptionPane.showInputDialog("Enter number to get square root");
  88.                 double sqrtA = Double.parseDouble(sqrtX);
  89.                 int result = (int)Math.sqrt(sqrtA);
  90.                
  91.                 JOptionPane.showMessageDialog(null, result);
  92.             }
  93.            
  94.         }while (counter <= 10);
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement