Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This uses switch cases to take numbers that are input and output words for math funcitons.
- *
- * @author (Rochita Chatterjee)
- * @version (Version1 1/17/17)
- */
- import java.util.*;
- import java.lang.*;
- public class EnglishLangCalculator
- {
- public static void main (String [] args)
- {
- String c;
- int a;
- int b;
- String wordA;
- String wordB;
- String symbC;
- Scanner scan = new Scanner (System.in);
- System.out.print("Please enter a single digit number: ");
- a = scan.nextInt();
- System.out.print("Please enter a single digit number: ");
- b = scan.nextInt();
- System.out.print("Please enter a math function: ");
- c = scan.next();
- switch ( a )
- {
- case 0:
- wordA = "zero";
- break;
- case 1:
- wordA = "one";
- break;
- case 2:
- wordA = "two";
- break;
- case 3:
- wordA = "three";
- break;
- case 4:
- wordA = "four";
- break;
- case 5:
- wordA = "five";
- break;
- case 6:
- wordA = "six";
- break;
- case 7:
- wordA = "seven";
- break;
- case 8:
- wordA = "eigth";
- break;
- case 9:
- wordA = "nine";
- break;
- }
- switch (b)
- {
- case 0:
- wordB = "zero";
- break;
- case 1:
- wordB = "one";
- break;
- case 2:
- wordB = "two";
- break;
- case 3:
- wordB = "three";
- break;
- case 4:
- wordB = "four";
- break;
- case 5:
- wordB = "five";
- break;
- case 6:
- wordB = "six";
- break;
- case 7:
- wordB = "seven";
- break;
- case 8:
- wordB = "eigth";
- break;
- case 9:
- wordB = "nine";
- break;
- }
- switch ( c)
- {
- case "+":
- symbC = "plus";
- System.out.println( wordA + symbC + wordB +"is" + (a+b));
- break;
- case "-":
- symbC = "minus";
- System.out.println( wordA + symbC + wordB +"is" + (a-b));
- break;
- case "*":
- symbC = "multiplied by";
- System.out.println( wordA + symbC + wordB +"is" + (a*b));
- break;
- case "/":
- symbC = "divided by";
- if(b == 0)
- {
- System.out.println("You cannot divide by zero");
- }
- else
- {
- System.out.println( wordA + symbC + wordB +"is" + (a/b));
- }
- break;
- case "^":
- symbC = "to the power";
- System.out.println( wordA + symbC + wordB +"is" + Math.pow(a,b));
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement