package simplecalculator;
import javax.swing.*;
import java.util.Scanner;
public class simplecalculator
{
static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
int choice;
do{
System.out.println(" *************************** ");
System.out.println(" Tonelete's Calculator ");
System.out.println(" *************************** ");
System.out.println(" ");
System.out.println(" (a) ADDITION ");
System.out.println(" (b) SUBTRACTION ");
System.out.println(" (c) MULTIPLICATION ");
System.out.println(" (d) DIVISION ");
System.out.println(" (e) QUIT ");
System.out.println(" ");
System.out.println(" *************************** ");
System.out.println("Your choice: ");
choice = input.nextInt();
}while (choice < 'a' || choice > 'e');
switch (choice)
{
case 'a':
add();
break;
case 'b':
minus();
break;
case 'c':
times();
break;
case 'd':
divide();
break;
case 'e':
System.exit(0);
break;
}
}
private static void add() {
int x, y, sum = 0;
int again;
String output;
JOptionPane.showMessageDialog(null, "ADDITION");
x = Integer.parseInt
(JOptionPane.showInputDialog(null, "Enter first Number"));
y = Integer.parseInt
(JOptionPane.showInputDialog(null, "Enter second Number"));
sum = x + y;
output = "The Sum is " + sum + ".";
JOptionPane.showMessageDialog(null, output);
System.out.println("Try Again? (Y/N): ");
again = input.next().charAt(0);
if (again == 'Y' || again == 'y');
}
private static void minus() {
int x, y, difference = 0;
int again;
String output;
JOptionPane.showMessageDialog(null, "SUBTRACTION");
x = Integer.parseInt
(JOptionPane.showInputDialog(null, "Enter first Number"));
y = Integer.parseInt
(JOptionPane.showInputDialog(null, "Enter second Number"));
difference = x - y;
output = "The difference is " + difference + ".";
JOptionPane.showMessageDialog(null, output);
System.out.println("Try Again? (Y/N): ");
again = input.next().charAt(0);
if (again == 'Y' || again == 'y');
}
private static void times() {
int x, y, product = 0;
int again;
String output;
JOptionPane.showMessageDialog(null, "MULTIPLICATION");
x = Integer.parseInt
(JOptionPane.showInputDialog(null, "Enter first Number"));
y = Integer.parseInt
(JOptionPane.showInputDialog(null, "Enter second Number"));
product = x * y;
output = "The Product is " + product + ".";
JOptionPane.showMessageDialog(null, output);
System.out.println("Try Again? (Y/N): ");
again = input.next().charAt(0);
if (again == 'Y' || again == 'y');
}
private static void divide() {
int x, y;
double quotient;
int again;
String output;
JOptionPane.showMessageDialog(null, "DIVISION");
x = (int) Double.parseDouble
(JOptionPane.showInputDialog(null, "Enter first Number"));
y = (int) Double.parseDouble
(JOptionPane.showInputDialog(null, "Enter second Number"));
quotient = x / y;
output = "The Quotient is " + quotient + ".";
JOptionPane.showMessageDialog(null, output);
System.out.println("Try Again? (Y/N): ");
again = input.next().charAt(0);
if (again == 'Y' || again == 'y');
}
}