Skip to content

Instantly share code, notes, and snippets.

@rubaiyat6370
Last active August 29, 2015 14:05
Show Gist options
  • Save rubaiyat6370/fd99628afa257bb8a886 to your computer and use it in GitHub Desktop.
Save rubaiyat6370/fd99628afa257bb8a886 to your computer and use it in GitHub Desktop.
Assignment of OOP1 on making a Basic Calculator
package edu.univdhaka.iit.calculator;
import java.util.Scanner;
public class MainApp {
@SuppressWarnings("resource")
public static void main(String[] args){
BasicCalculator basicCalculator = new BasicCalculator();
for(;;){
System.out.println("Press \n 1 for Add\n 2 for Subtraction\n 3 for Division\n 4 for Multiplication\n ");
System.out.println("Press \n 5 for Power \n 6 for SquareRoot\n 7 for Square\n 8 for Percentage\n ");
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
int a,b,c;
if(choice==1){
System.out.println("Enter 3 numbers for add :");
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
System.out.println("The Add result is :" + basicCalculator.addition(a,b,c));
}
else if(choice==2){
System.out.println("Enter 2 numbers for Subtraction :");
a = input.nextInt();
b = input.nextInt();
System.out.println("The Subtraction result is :"+ basicCalculator.subtraction(a, b));
}
else if(choice==3){
System.out.println("Enter 2 number for Division :");
a = input.nextInt();
b = input.nextInt();
if(b!=0){
System.out.println("The Division result is :"+ basicCalculator.division(a, b));
}
else System.out.println("The result is undefined!!");
}
else if(choice==4){
System.out.println("Enter 3 numbers for Multiplication :");
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
System.out.println("The Multiplication result is :"+ basicCalculator.multiplication(a,b,c));
}
else if(choice==5){
System.out.println("Enter 2 numbers for Power :");
a = input.nextInt();
b = input.nextInt();
System.out.println("The Power result is :"+ basicCalculator.power(a, b));
}
else if(choice==6){
System.out.println("Enter a number: ");
a=input.nextInt();
System.out.println("Square root:"+basicCalculator.sqrt(a));
}
else if(choice==7){
System.out.println("Enter a number: ");
a=input.nextInt();
System.out.println("Percentage:"+basicCalculator.square(a));
}
else if(choice==8){
System.out.println("Enter a number: ");
a=input.nextInt();
System.out.println("Percentage:"+basicCalculator.percent(a));
}
else break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment