Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import comp102x.IO;
- import java.util.Scanner;
- /**
- * Write a description of class Calculator here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Calculator
- {
- Scanner user_input = new Scanner(System.in);
- int a=0,b=0;
- int answer = 0;
- String op = "Continue";
- public void numbers() {
- IO.outputln("a = ");
- a = user_input.nextInt();
- IO.outputln("b = ");
- b = user_input.nextInt();
- IO.outputln("add/sub/mul/div/rem");
- String Menu = user_input.next();
- if (Menu.equals("add")) {
- answer = a + b;
- }
- else if (Menu.equals("sub")) {
- answer = a - b;
- }
- else if (Menu.equals("mul")) {
- answer = a * b;
- }
- else if (Menu.equals("div")) {
- answer = a / b;
- }
- else if (Menu.equals("rem")) {
- //this is where I want it to divide with a remainder.
- }
- System.out.println("a = " + a + "," + " b = " + b + ", function = " + Menu);
- System.out.println("Answer = " + answer);
- System.out.println("What is your option? Continue or Exit");
- op = user_input.next();
- if (op.equals("Continue")) {
- numbers();
- }
- if (op.equals("Exit")) {
- user_input.close();
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement