Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

package newpackage;

import java.util.Scanner;
public class Activity71 {
public static void main(String args[]) {

//Question
Scanner choice = new Scanner(System.in);
System.out.println(
"My Simple Calculator \n A) Addition \n B) Subtraction \n C) Multiplication \n D) Division
\nKindly enter the letter of your choice: (Case Sensitive)");
String letter = choice.nextLine();

//Letters
String a = "A";
String b = "B";
String c = "C";
String d = "D";

//If addition
if (letter.equals(a)) {
System.out.println("Your choice is addition");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 + num2;
System.out.println("The sum is " + result);
}

//If subtraction
if (letter.equals(b)) {
System.out.println("Your choice is subtraction");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 - num2;
System.out.println("The difference is " + result);
}

//If multiplication
if (letter.equals(c)) {
System.out.println("Your choice is multiplication");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 * num2;
System.out.println("The product is " + result);
}

//If division
if (letter.equals(d)) {
System.out.println("Your choice is division");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 / num2;
System.out.println("The quotient is " + result);
}
}
}

You might also like