Created
August 14, 2014 23:56
-
-
Save AliZafar120/86f4ef6764e72119fac9 to your computer and use it in GitHub Desktop.
Main for running the BasicCalculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.univdhaka.iit.calculator; | |
import java.math.BigInteger; | |
import java.util.Scanner; | |
public class CalculatorMain { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
BasicCalculator calc = new BasicCalculator(); | |
int choice; | |
do | |
{ | |
System.out.println("Enter your choice\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Power\n6.Squareroot\n7.Percentage"); | |
choice = input.nextInt(); | |
if(choice==1 || choice==2 ||choice==3 || choice==4) | |
{ | |
System.out.println("Enter the 1st Number :"); | |
String X= input.next(); | |
BigInteger num1 = new BigInteger(X); | |
System.out.println("Enter the 2nd Number :"); | |
String Y= input.next(); | |
BigInteger num2 = new BigInteger(Y); | |
switch(choice) | |
{ | |
case 1 :System.out.println("The sum of the numbers are "+ calc.add(num1, num2));break; | |
case 2 : System.out.println("The subtraction of the numbers are "+ calc.subtract(num1, num2));break; | |
case 3 :System.out.println("The multiplication of the numbers are "+ calc.multiply(num1, num2));break; | |
case 4 :System.out.println("The division of the numbers are "+ calc.divide(num1, num2));break; | |
} | |
} | |
switch(choice) | |
{ | |
case 5 : | |
System.out.println("Enter the Number :"); | |
String x= input.next(); | |
BigInteger num3 = new BigInteger(x); | |
System.out.println("Given Number to the power :"); | |
int num4= input.nextInt(); | |
System.out.println("The exponent of the number is "+ calc.exponent(num3,num4));break; | |
case 6 : | |
System.out.println("Enter the number"); | |
double i= input.nextDouble(); | |
System.out.println("The sqrt is "+ calc.squareroot(i)); | |
case 7:System.out.println("Enter the number"); | |
int y=input.nextInt(); | |
System.out.println("Number's % ?"); | |
int z=input.nextInt(); | |
System.out.println("The percentage of the number is "+ calc.percentage(y, z));break; | |
} | |
System.out.println("Want to do more calculation ?press 8 for No and 9 for yes"); | |
choice = input.nextInt(); | |
}while(choice!=8); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
switch was used twice bcz it showed error if i relate it with other cases i.e 1-4 with 5-7