0% found this document useful (0 votes)
5 views4 pages

Calculator Game

This Java program implements a basic calculator that performs various arithmetic and trigonometric operations based on user input. It continuously prompts the user for two numbers and an operation until terminated. The Calculator class contains methods for each operation, providing results for addition, subtraction, multiplication, division, and more.

Uploaded by

vaishnavs2811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Calculator Game

This Java program implements a basic calculator that performs various arithmetic and trigonometric operations based on user input. It continuously prompts the user for two numbers and an operation until terminated. The Calculator class contains methods for each operation, providing results for addition, subtraction, multiplication, division, and more.

Uploaded by

vaishnavs2811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.util.

Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("This is a calculator");
Scanner s = new Scanner(System.in);

Calculator calc = new Calculator();


while (true) {
System.out.println("Enter a number");
int myInt = s.nextInt();
System.out.println("Enter another number");
int altInt = s.nextInt();
System.out.println("""
What operation?
1. Add
2. Subtract
3. Multiply
4. Divide
5. Integer Divide
6. Modulo
7. Round
8. Exponent
9. Factorial
10. Floor
11. Ceiling
12. Sine
13. Cosine
14. Tangent
15. Cosecant
16. Secant
17. Cotangent
""");
String operation = s.next();
if (operation.equals("1")) {
calc.add(myInt, altInt);
}
else if (operation.equals("2")) {
calc.subtract(myInt, altInt);
}
else if (operation.equals("3")) {
calc.multiply(myInt, altInt);
}
else if (operation.equals("4")) {
calc.divide(myInt, altInt);
}
else if (operation.equals("5")) {
calc.integer_divide(myInt, altInt);
}
else if (operation.equals("6")) {
calc.modulo(myInt, altInt);
}
else if (operation.equals("7")) {
calc.round(myInt, altInt);
}
else if (operation.equals("8")) {
calc.exponent(myInt, altInt);
}
else if (operation.equals("9")) {
calc.factorial(myInt, altInt);
}
else if (operation.equals("10")) {
calc.floor(myInt, altInt);
}
else if (operation.equals("11")) {
calc.ceiling(myInt, altInt);
}
else if (operation.equals("12")) {
calc.sin(myInt, altInt);
}
else if (operation.equals("13")) {
calc.cos(myInt, altInt);
}
else if (operation.equals("14")) {
calc.tan(myInt, altInt);
}
else if (operation.equals("15")) {
calc.csc(myInt, altInt);
}
else if (operation.equals("16")) {
calc.sec(myInt, altInt);
}
else if (operation.equals("17")) {
calc.cot(myInt, altInt);
}
else {
System.out.println("Are you stupid?");
}
}
}
}
class Calculator {
int x;

public Calculator() {
x = 5;
System.out.println("Welcome to calculator");
}

public void add(int num1, int num2) {


System.out.println("The sum of " + num1 + " and " + num2 + " is " +
(num1+num2));
}

public void subtract(int num1, int num2) {


System.out.println("The difference of " + num1 + " and " + num2 + " is " +
(num1-num2));
}

public void multiply(int num1, int num2) {


System.out.println("The product of " + num1 + " and " + num2 + " is " +
(num1*num2));
}

public void integer_divide(int num1, int num2) {


System.out.println("The floor of the quotient of " + num1 + " and " + num2
+ " is " + (num1/num2));
}

public void modulo(int num1, int num2) {


System.out.print("The modulo of " + num1 + " and " + num2 + " is " +
(num1%num2));
}

public void divide(int num1, int num2) {


System.out.println("The quotient of " + num1 + " and " + num2 + " is " +
( (double) num1/ (double) num2));
}

public void exponent(int num1, int num2) {


System.out.println(num1 + " to the power of " + num2 + " is " +
Math.pow(num1, num2));
}

public void round(double num1, double num2) {


System.out.println("The rounding of " + num1 + " is " + (int) (num1+0.5) +
" and the rounding of " + num2 + " is " + (int) (num2+0.5));
}

public void factorial(int num1, int num2) {


int a = 1;
for (int i = 1; i <= num1; i++) {
a *= i;
}
int b = 1;
for (int i = 1; i <= num2; i++) {
b *= i;
}

System.out.println("The factorial of " + num1 + " is " + a + " and the


factorial of " + num2 + " is " + b);
}

public void floor(double num1, double num2) {


System.out.println("The floors of " + num1 + " and " + num2 + " are " +
(int)num1 + " and " + (int)num2);
}

public void ceiling(double num1, double num2) {


System.out.println("The ceilings of " + num1 + " and " + num2 + " are " +
((int)num1 + 1) " and " + ((int)num2)+1);
}

public void sin(double num1, double num2) {


double sin1 = Math.sin(num1);
double sin2 = Math.sin(num2);
System.out.println("The sin of " + num1 + " is " + sin1 + " and the sin of"
+ num2 + " is " + sin2);
}

public void cos(double num1, double num2) {


double cos1 = Math.sin(num1);
double cos2 = Math.sin(num2);
System.out.println("The cos of " + num1 + " is " + cos1 + " and the cos of"
+ num2 + " is " + cos2);
}
public void tan(double num1, double num2) {
System.out.println("The tan of " + num1 + " is " + Math.tan(num1) + " and
the tan of" + num2 + " is " + Math.tan(num2));
}

public void csc(double num1, double num2) {


System.out.println("The csc of " + num1 + " is " + 1/Math.sin(num1) + "
and the csc of " + num2 + " is " + 1/Math.sin(num2));
}

public void sec(double num1, double num2) {


System.out.println("The sec of " + num1 + " is " + 1/Math.cos(num1) + "
and the sec of " + num2 + " is " + 1/Math.cos(num2));
}

public void cot(double num1, double num2) {


System.out.println("The cot of " + num1 + " is " + 1/Math.tan(num1) + "
and the cot of " + num2 + " is " + 1/Math.tan(num2));
}

You might also like