Vous êtes sur la page 1sur 6

import java.util.

Scanner;
public class yusrina_calculator {
int choose, back, insert, n;
double result, num1, num2;
public static void main(String[] args) {
// TODO Auto-generated method stub
yusrina_calculator ririn = new yusrina_calculator();
System.out.println("
WELCOME TO CALCULATOR SCIENCET
IFIC ");
System.out.println("");
ririn.menu();
}
Scanner rin = new Scanner(System.in);
public void menu() {
System.out.println("Code Selection");
System.out.println("1. Addition");
System.out.println("2. Substraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Modulo");
System.out.println("6. Root");
System.out.println("7. Power");
System.out.println("8. Percent");
System.out.println("9. Permutation");
System.out.println("10. Combination");
System.out.println("11. Log");
System.out.println("12. Sin");
System.out.println("13. Cos");
System.out.println("14. Tan");
System.out.println("Input your code selection :) :");
choose = rin.nextInt();
if (choose == 1) {
add();
} else if (choose ==
subs();
} else if (choose ==
multi();
} else if (choose ==
div();
} else if (choose ==
mod();
} else if (choose ==
root();
} else if (choose ==
power();
} else if (choose ==
percent();
} else if (choose ==
permut();
} else if (choose ==
combin();
} else if (choose ==
log();
} else if (choose ==
sin();

2) {
3) {
4) {
5) {
6) {
7) {
8) {
9) {
10) {
11) {
12) {

} else if (choose == 13) {


cos();
} else if (choose == 14) {
tan();
} else {
System.out.print("Input number that exist in code select
ion : ");
menu();
}
}
public void final_menu() {
System.out.println("Input 0 for menus or 22 for exit");
back = rin.nextInt();
if (back == 0) {
menu();
} else if (back == 22) {
System.out.println("----------Thank you for using calcul
ator sciencetific----------");
}
}
public void add() {
System.out.println("How long number do you want to calculate?");
int n = rin.nextInt();
if (n < 1) {
System.out.println("Just insert positive number");
add();
} else {
int[] a = new int[n];
int result = 0;
System.out.println("Enter the number");
for (int i = 0; i < n; i++) {
System.out.print("number - " + (i) + ": ");
a[i] = rin.nextInt();
result += a[i];
}
System.out.println("Addition result = " + result);
}
final_menu();
}
public void subs() {
System.out.println("How long number do you want to calculate?");
int n = rin.nextInt();
if (n < 1) {
System.out.println("Just insert positive number");
subs();
} else {
int[] a = new int[n];
int result = 0;
System.out.println("Enter the number");
for (int i = 0; i < n; i++) {
System.out.print("number - " + (i) + ": ");
a[i] = rin.nextInt();
if (i == 0) {
result += a[i];
} else {
result -= a[i];
}

}
System.out.println("Substraction result = " + result);
}
final_menu();
}
public void multi() {
System.out.println("How long number do you want to calculate?");
int n = rin.nextInt();
if (n < 1) {
System.out.println("Just insert positive number");
multi();
} else {
int[] a = new int[n];
int result = 0;
System.out.println("Enter the number");
for (int i = 0; i < n; i++) {
System.out.print("number - " + (i) + ": ");
a[i] = rin.nextInt();
if (i == 0) {
result += a[i];
} else {
result *= a[i];
}
}
System.out.println("Multiplication result = " + result);
}
final_menu();
}
public void div() {
System.out.println("How long number do you want to calculate?");
int n = rin.nextInt();
if (n < 1) {
System.out.println("Just insert positive number");
multi();
} else {
int[] a = new int[n];
int result = 0;
System.out.println("Enter the number");
for (int i = 0; i < n; i++) {
System.out.print("number - " + (i) + ": ");
a[i] = rin.nextInt();
if (i == 0) {
result += a[i];
} else {
result /= a[i];
}
}
System.out.println("Division result = " + result);
}
final_menu();
}
public void mod() {
System.out.print("Input number (1) that you want to calculate :
");
num1 = rin.nextDouble();
System.out.print("Input number (2) that you want to calculate :
");

num2 = rin.nextDouble();
result = num1 % num2;
System.out.println("Modulo result = " + result);
final_menu();
}
public void root() {
System.out.print("Insert 2 for square root or 3 for cube root :
");
insert = rin.nextInt();
System.out.print("Input number of root : ");
num1 = rin.nextDouble();
while (num1 < 0) {
System.out.print("Input positive number of root : ");
num1 = rin.nextDouble();
}
if (insert == 2) {
result = Math.sqrt(num1);
System.out.println("Root result = " + result);
final_menu();
} else if (insert == 3) {
result = Math.cbrt(num1);
System.out.println("Root result = " + result);
final_menu();
}
}
public void power() {
System.out.print("Input base number that you want to calculate
: ");
num1 = rin.nextDouble();
System.out.print("Input number of power : ");
num2 = rin.nextDouble();
result = Math.pow(num1, num2);
System.out.println("Power result = " + result);
final_menu();
}
public void percent() {
System.out.print("Input number that you want to calculate : ");
num1 = rin.nextDouble();
result = 100 * (1 / num1);
System.out.println("Percent result = " + result + "%");
final_menu();
}
public void permut() {
System.out.print("Input the sample's number of permutation : ");
num1 = rin.nextDouble();
System.out.print("Input the event's number of permutation : ");
num2 = rin.nextDouble();
double num3 = num1 - num2;
double result1 = 1;
double result2 = 1;
double result3 = 1;
for (int i = 1; i <= num1; i++) {
result1 = result1 * i;
}
for (int i = 1; i <= num2; i++) {
result2 = result2 * i;

}
for (int i = 1; i <= num3; i++) {
result3 = result3 * i;
}
double permutationresult = result1 / result3;
System.out.println("Permutation result : " + permutationresult);
final_menu();
}
public void combin() {
System.out.print("Input the sample's number of combination : ");
num1 = rin.nextDouble();
System.out.print("Input the event's number of combination : ");
num2 = rin.nextDouble();
double num3 = num1 - num2;
double result1 = 1;
double result2 = 1;
double result3 = 1;
for (int i = 1; i <= num1; i++) {
result1 = result1 * i;
}
for (int i = 1; i <= num2; i++) {
result2 = result2 * i;
}
for (int i = 1; i <= num3; i++) {
result3 = result3 * i;
}
double combinationresult = result1 / (result3 * result2);
System.out.println("Combination : " + combinationresult);
final_menu();
}
public void log() {
System.out.print("Input number that you want to calculate : ")
;
num1 = rin.nextDouble();
result = Math.log(num1);
System.out.println("Log result = " + result);
final_menu();
}
public void sin() {
System.out.print("Input degree that you want to calculate : ");
num1 = rin.nextDouble();
result = Math.sin(Math.toRadians(num1));
System.out.println("Sin result = " + result);
final_menu();
}
public void cos() {
System.out.print("Input degree that you want to calculate : ");
num1 = rin.nextDouble();
result = Math.cos(Math.toRadians(num1));
System.out.println("Cos result = " + result);
final_menu();
}
public void tan() {
System.out.print("Input degree that you want to calculate : ");
num1 = rin.nextDouble();

result = Math.tan(Math.toRadians(num1));
System.out.println("Sin result = " + result);
final_menu();
}
}

Vous aimerez peut-être aussi