Question: How do I make my calculator program ask the user after each calculation to either end the program or quit or to continue to use

How do I make my calculator program ask the user after each calculation to either end the program or quit or to continue to use the calculator before repeating the "Welcome to Calculator Calculations" thing? Its not working for me. What code do I need to add? Also, how do I add the functions for sin cos and tan in this calculator? I need the code to see how it would work for trigonometric functions both degrees and radians if possible. Also, I want my code to reject any input other than a number and repeat itself to ask the user to enter numbers again. Also, I want the calculator to be able to calculate values like 5/9 would be 0.55, I think I would need to add a double but i dont know where to add.Thank you. Please get this problem done ASAP!

This is the output:

Welcome to Calculator Calculations!

--------------------------------------

Enter two numbers below:

Please enter the first number:

23

Please enter the second number:

39

What operation would you like to choose for these numbers?

Your options are: +, -, /, *

Please type one of the options here:

Type Q to quit

+

62

Would you like to calculate more or quit?

Welcome to Calculator Calculations!

--------------------------------------

Enter two numbers below:

Please enter the first number:

THIS IS MY CODE BELOW:

package calculator;

public abstract class MyCalculator {

public static void main(String args[]) {

OtherOps op = null;

while(true) {

op = new OtherOps();

while(op.op != '+' && op.op != '-'&& op.op != '*' && op.op !='/') {

op.set_op();

}

switch (op.op) {

case '*': op.result = op.multiply(); break;

case '/': op.result = op.divide(); break;

case '+': op.result = op.add(); break;

case '-': op.result = op.subtract(); break;

case 'Q': System.out.println("Exiting program"); break;

default: break;

}

System.out.println(op.result);

}

}

}

package calculator;

import java.util.Scanner;

public class Operators {

private int num1;

private int num2;

char op;

private final Scanner sca;

public int result;

char command;

public Operators() {

sca = new Scanner(System.in);

System.out.println("Welcome to Calculator Calculations!");

System.out.println("--------------------------------------");

System.out.println("Enter two numbers below:");

System.out.println("Please enter the first number:");

num1 = sca.nextInt();

System.out.println("Please enter the second number:");

num2 = sca.nextInt();

System.out.println("What operation would you like to choose for these numbers?");

System.out.println("Your options are: "+ "+, " + "-, " + "/, " + "*");

System.out.println("Please type one of the options here:");

System.out.println("Type Q to quit");

op = sca.next().charAt(0);

if(op == '+' ||op == '-' || op == '/' || op == '*') {

return;

}

}

public char set_op(){

op = (char)sca.nextShort();

return op;

}

public int add() {

return (this.num1 + this.num2);

}

public int subtract() {

return this.num1 - this.num2;

}

public int getX() {

return this.num1;

}

public int getY() {

return this.num2;

}

public void setX(int x) {

this.num1 = x;

}

public void setY(int y) {

this.num2 = y;

}

}

/*public int Sin(int x) {

int z;

z = Sin(x);

return z;

}

}

*/

package calculator;

public class OtherOps extends Operators {

public OtherOps() {

super();

}

public int multiply() {

return (int) (this.getX() * this.getY());

}

public int divide() {

return (int) (this.getX() / this.getY());

}

}

TO THE COMMENT PERSON BELOW:Yes,It would be great if you could include that in the menu.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!