How do I fix the result? import java.lang.*; 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.equals("+")) standardCalcHelper('+'); else if(operation.equals("-")) standardCalcHelper('-'); else if(operation.equals("*")) standardCalcHelper('*'); else if(operation.equals("/")) standardCalcHelper('/'); else if(operation.equals("sin")) scientificCalcHelper('s'); else if(operation.equals("cos")) scientificCalcHelper('c'); else if(operation.equals("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("Enter a number in radians to find the " + 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); if(operation == 's')     System.out.println("Result: " + Math.sin(number)); else if(operation=='c')     System.out.println("Result: " + Math.cos(number)); else if(operation == 't')     System.out.println("Result: " + Math.tan(number)); } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

How do I fix the result?

import java.lang.*;
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.equals("+")) standardCalcHelper('+');
else if(operation.equals("-")) standardCalcHelper('-');
else if(operation.equals("*")) standardCalcHelper('*');
else if(operation.equals("/")) standardCalcHelper('/');
else if(operation.equals("sin")) scientificCalcHelper('s');
else if(operation.equals("cos")) scientificCalcHelper('c');
else if(operation.equals("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("Enter a number in radians to find the " + 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);
if(operation == 's')
    System.out.println("Result: " + Math.sin(number));
else if(operation=='c')
    System.out.println("Result: " + Math.cos(number));
else if(operation == 't')
    System.out.println("Result: " + Math.tan(number));
}

}

Input
Standard + 2 99 47 Y Scientific cos 2 Y Scientific sin 3 N
Enter the calculator mode: Standard/Scientific?
The calculator will operate in standard mode.
Enter '+' for addition, '-' for subtractions, '*' for multiplication,
How many numbers do you want to add?
Enter 2 numbers
Result: 146.0
Your output
Do you want to start over? (Y/N)
Enter the calculator mode: Standard/Scientific?
The calculator will operate in scientific mode.
Enter '+' for addition,
'-' for subtractions, '*' for multiplication, '/
Enter a number in radians to find the cosine
Enter the calculator mode: Standard/Scientific?
The calculator will operate in standard mode.
Enter '+' for addition,
'-' for subtractions, '*' for multiplication, '/
How many numbers do you want to add?
Enter 2 numbers
Result: 146.0
Do you want to start over? (Y/N)
Enter the calculator mode: Standard/Scientific?
The calculator will operate in scientific mode.
Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/
Expected output
Enter a number in radians to find the cosine
Result: -0.4161468365471424
Do you want to start over? (Y/N)
Enter the calculator mode: Standard/Scientific?
The calculator will operate in scientific mode.
Enter '+' for addition, '-' for subtractions,
*' for multiplication,
Enter a number in radians to find the sine
Result: 0.1411200080598672
Do you want to start over? (Y/N)
Goodbye
Transcribed Image Text:Input Standard + 2 99 47 Y Scientific cos 2 Y Scientific sin 3 N Enter the calculator mode: Standard/Scientific? The calculator will operate in standard mode. Enter '+' for addition, '-' for subtractions, '*' for multiplication, How many numbers do you want to add? Enter 2 numbers Result: 146.0 Your output Do you want to start over? (Y/N) Enter the calculator mode: Standard/Scientific? The calculator will operate in scientific mode. Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/ Enter a number in radians to find the cosine Enter the calculator mode: Standard/Scientific? The calculator will operate in standard mode. Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/ How many numbers do you want to add? Enter 2 numbers Result: 146.0 Do you want to start over? (Y/N) Enter the calculator mode: Standard/Scientific? The calculator will operate in scientific mode. Enter '+' for addition, '-' for subtractions, '*' for multiplication, '/ Expected output Enter a number in radians to find the cosine Result: -0.4161468365471424 Do you want to start over? (Y/N) Enter the calculator mode: Standard/Scientific? The calculator will operate in scientific mode. Enter '+' for addition, '-' for subtractions, *' for multiplication, Enter a number in radians to find the sine Result: 0.1411200080598672 Do you want to start over? (Y/N) Goodbye
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY