How do I fix the code for sin, cos, and tan so I can get a result? import java.util.Scanner; // import the Scanner class public class Main { public static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { boolean doItAgain = false; do { doItAgain = false; calcType(); System.out.println("Do you want to start over? (Y/N)"); //Scanner keyboard = new Scanner(System.in); String decision = keyboard.next(); if(decision.equals("Y")) { doItAgain = true; } } while(doItAgain); System.out.println("Goodbye"); } public static void calcType() { String mode; System.out.println("Enter the calculator mode: Standard/Scientific?"); //Scanner keyboard = new Scanner(System.in); mode = keyboard.next(); if(mode.equals("Standard")) { standard(); } else if (mode.equals("Scientific")) { scientific(); } else System.out.println("Unknown calculator type: " + mode); } public static void standard() { System.out.println("The calculator will operate in standard mode."); boolean doItAgain; do { doItAgain = false; System.out.println("Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division"); String operation; //Scanner keyboard = new Scanner(System.in); operation = keyboard.next(); //System.out.println("DB: operation = " + operation); if(operation.equals("+") ) standardCalcHelper('+'); else if(operation.equals("-")) standardCalcHelper('-'); else if(operation.equals("*")) standardCalcHelper('*'); else if(operation.equals("/")) standardCalcHelper('/'); else { System.out.println("Invalid operator " + operation); doItAgain = true; } } while(doItAgain); } public static void scientific() { System.out.println("The calculator will operate in scientific mode."); boolean doItAgain; do { doItAgain = false; System.out.println("Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:"); String operation; // Scanner keyboard = new Scanner(System.in); operation = keyboard.next(); if(operation == "+") standardCalcHelper('+'); else if(operation == "-") standardCalcHelper('-'); else if(operation == "*") standardCalcHelper('*'); else if(operation == "/") standardCalcHelper('/'); else if(operation == "sin") scientificCalcHelper('s'); else if(operation == "cos") scientificCalcHelper('c'); else if(operation == "tan") scientificCalcHelper('t'); else { System.out.println("Invalid operator " + operation); doItAgain = true; } } while(doItAgain); } static String getOperationName(char operation) { if(operation == '+') return "add"; else if(operation == '-') return "subtract"; else if(operation == '*') return "multiply"; else if(operation == '/') return "divide"; else if(operation == 's') return "sine"; else if(operation == 'c') return "cosine"; else if(operation == 't') return "tangent"; return ""; } static void standardCalcHelper(char operation) { //Scanner sc = new Scanner(System.in); System.out.println("How many numbers do you want to " + getOperationName(operation) + "?"); int times = keyboard.nextInt(); // if(times > 0) System.out.println("Enter " + times + " numbers"); double result = keyboard.nextDouble(); for (int i = 0; i < times-1; i++){ if(operation == '+') result += keyboard.nextDouble(); else if(operation == '-') result -= keyboard.nextDouble(); else if(operation == '*') result *= keyboard.nextDouble(); else if(operation == '/') result /= keyboard.nextDouble(); } System.out.println("Result: " + result); } static void scientificCalcHelper(char operation) { System.out.println("How many numbers do you want to " + getOperationName(operation)); double number; Scanner scanner =new Scanner(System.in); number = scanner.nextInt(); // double radian = keyboard.nextDouble(); // double result = Math.sin(radian); // System.out.println( "Result: " + result); System.out.println("Result: " + Math.sin(number)); System.out.println("Result: " + Math.cos(number)); System.out.println("Result: " + Math.tan(number)); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

How do I fix the code for sin, cos, and tan so I can get a result?

import java.util.Scanner; // import the Scanner class

public class Main {

public static Scanner keyboard = new Scanner(System.in);

public static void main(String[] args) {

boolean doItAgain = false;
do
{
doItAgain = false;
calcType();
System.out.println("Do you want to start over? (Y/N)");
//Scanner keyboard = new Scanner(System.in);
String decision = keyboard.next();
if(decision.equals("Y")) {
doItAgain = true;
}
}
while(doItAgain);
System.out.println("Goodbye");
}

public static void calcType() {
String mode;
System.out.println("Enter the calculator mode: Standard/Scientific?");
//Scanner keyboard = new Scanner(System.in);
mode = keyboard.next();
if(mode.equals("Standard")) {
standard();
}
else if (mode.equals("Scientific")) {
scientific();
}
else
System.out.println("Unknown calculator type: " + mode);
}

public static void standard() {
System.out.println("The calculator will operate in standard mode.");
boolean doItAgain;
do
{
doItAgain = false;
System.out.println("Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division");

String operation;
//Scanner keyboard = new Scanner(System.in);
operation = keyboard.next();
//System.out.println("DB: operation = " + operation);

if(operation.equals("+") ) standardCalcHelper('+');
else if(operation.equals("-")) standardCalcHelper('-');
else if(operation.equals("*")) standardCalcHelper('*');
else if(operation.equals("/")) standardCalcHelper('/');
else {
System.out.println("Invalid operator " + operation);
doItAgain = true;
}
}
while(doItAgain);
}

public static void scientific() {
System.out.println("The calculator will operate in scientific mode.");
boolean doItAgain;
do
{
doItAgain = false;
System.out.println("Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:");
String operation;
// Scanner keyboard = new Scanner(System.in);
operation = keyboard.next();

if(operation == "+") standardCalcHelper('+');
else if(operation == "-") standardCalcHelper('-');
else if(operation == "*") standardCalcHelper('*');
else if(operation == "/") standardCalcHelper('/');
else if(operation == "sin") scientificCalcHelper('s');
else if(operation == "cos") scientificCalcHelper('c');
else if(operation == "tan") scientificCalcHelper('t');
else {
System.out.println("Invalid operator " + operation);
doItAgain = true;
}
}
while(doItAgain);
}

static String getOperationName(char operation) {
if(operation == '+') return "add";
else if(operation == '-') return "subtract";
else if(operation == '*') return "multiply";
else if(operation == '/') return "divide";
else if(operation == 's') return "sine";
else if(operation == 'c') return "cosine";
else if(operation == 't') return "tangent";

return "";
}

static void standardCalcHelper(char operation) {

//Scanner sc = new Scanner(System.in);
System.out.println("How many numbers do you want to " + getOperationName(operation) + "?");
int times = keyboard.nextInt();
// if(times > 0)
System.out.println("Enter " + times + " numbers");
double result = keyboard.nextDouble();
for (int i = 0; i < times-1; i++){
if(operation == '+') result += keyboard.nextDouble();
else if(operation == '-') result -= keyboard.nextDouble();
else if(operation == '*') result *= keyboard.nextDouble();
else if(operation == '/') result /= keyboard.nextDouble();
}
System.out.println("Result: " + result);
}

static void scientificCalcHelper(char operation) {
System.out.println("How many numbers do you want to " + getOperationName(operation));
double number;
Scanner scanner =new Scanner(System.in);
number = scanner.nextInt();
// double radian = keyboard.nextDouble();
// double result = Math.sin(radian);
// System.out.println( "Result: " + result);
System.out.println("Result: " + Math.sin(number));
System.out.println("Result: " + Math.cos(number));
System.out.println("Result: " + Math.tan(number));
}

}

 

 

**Calculator Mode and Operator Guide**

When using a calculator, you have the option to select between two modes: Standard and Scientific. Choosing the Scientific mode enables additional mathematical functions.

**Instructions for Using the Scientific Calculator:**

1. **Entering Calculator Mode:**
   - You are prompted to choose a mode: Standard/Scientific.
   - For advanced calculations, select Scientific mode.

2. **Operator Instructions:**
   - Use the following symbols for operations:
     - `+`: Addition
     - `-`: Subtraction
     - `*`: Multiplication
     - `/`: Division
     - `sin`: Sine function (for angle calculations)

3. **Troubleshooting Invalid Operators:**
   - If an invalid operator is entered, such as `cos` (cosine), it will be flagged.
   - Enter valid operations only, as listed above.

4. **Examples of Invalid Operations:**
   - Inputting invalid symbols like `0` or `Y` will not be recognized by the calculator.
   - Ensure all inputs correspond to acceptable mathematical operators.

This guide assists users in effectively operating a scientific calculator, ensuring correct input for desired mathematical computations.
Transcribed Image Text:**Calculator Mode and Operator Guide** When using a calculator, you have the option to select between two modes: Standard and Scientific. Choosing the Scientific mode enables additional mathematical functions. **Instructions for Using the Scientific Calculator:** 1. **Entering Calculator Mode:** - You are prompted to choose a mode: Standard/Scientific. - For advanced calculations, select Scientific mode. 2. **Operator Instructions:** - Use the following symbols for operations: - `+`: Addition - `-`: Subtraction - `*`: Multiplication - `/`: Division - `sin`: Sine function (for angle calculations) 3. **Troubleshooting Invalid Operators:** - If an invalid operator is entered, such as `cos` (cosine), it will be flagged. - Enter valid operations only, as listed above. 4. **Examples of Invalid Operations:** - Inputting invalid symbols like `0` or `Y` will not be recognized by the calculator. - Ensure all inputs correspond to acceptable mathematical operators. This guide assists users in effectively operating a scientific calculator, ensuring correct input for desired mathematical computations.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education