Question: LANGUAGE IS JAVA EDITS NEEDED: ERROR WHEN DIVIDING BY ZERO RESTART THE APPLICATION WHEN OPERATION IS OVER. Would you like to start again (Y/N)? USER
LANGUAGE IS JAVA
EDITS NEEDED: ERROR WHEN DIVIDING BY ZERO RESTART THE APPLICATION WHEN OPERATION IS OVER. "Would you like to start again (Y/N)?" USER PICKS "Y"- restarts application USER PICKS "N" - until next time
CODE:
import java.util.Scanner; public class CalculatorProject { public static void main (String[] args) { Scanner yurr = new Scanner(System.in); String mode; double i; String choice; System.out.println("Enter the calculator mode: Standard/Scientific?"); mode = yurr.next(); if(mode.equals("Scientific")) { System.out.print("Enter '+' for addition, '-' for substractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:"); System.out.println("Enter Choice: "); choice = yurr.next(); switch(choice) { case "+": double x, results = 0.0, number= 0/0; System.out.println("How many numbers do you want to add:"); x = yurr.nextDouble(); System.out.println("Enter " + x + " numbers:"); for ( i = 1.0; i <= x; i++) { number = yurr.nextInt(); results = results + number; } System.out.println("The result will be " + results); break; case "-": double x1, results1 = 0.0, number1 = 0.0; System.out.println("How many numbers do you want to subtract:"); x1 = yurr.nextDouble(); System.out.println("Enter " + x1 + " numbers:"); for ( i = 1.0; i <= x1; i++) { number1 = yurr.nextInt(); results1 = results1 - number1; } System.out.println("The result will be " + results1); break; case "*": double x2, results2 = 1.0, number2=0.0; System.out.println("How many numbers do you want to add:"); x2 = yurr.nextDouble(); System.out.println("Enter " + x2 + " numbers:"); for ( i = 1.0; i <= x2; i++) { number2 = yurr.nextInt(); results2 = results2 * number2; } System.out.println("The result will be " + results2); break; case "/": double x3, results3 = 1.0, number3=0.0; System.out.println("How many numbers do you want to add:"); x3 = yurr.nextDouble(); System.out.println("Enter " + x3 + " numbers:"); for ( i = 1.0; i <= x3 - 1.0; i++) { number3 = yurr.nextInt(); results3 = results3 / number3; } System.out.println("The result will be " + results3); break; case "sin": double radian; System.out.print("Enter number in radians to find sin:"); radian = yurr.nextDouble(); System.out.println("Result:" + Math.sin(radian)); break; case "cos": double radian1; System.out.print("Enter number in radians to find cos:"); radian1 = yurr.nextDouble(); System.out.println("Result:" + Math.cos(radian1)); break; case "tan": double radian2; System.out.print("Enter number in radians to find tan:"); radian2 = yurr.nextDouble(); System.out.println("Result:" + Math.tan(radian2)); break; case "e": System.out.println("Invalid operation entered"); } } else if (mode.equals("Standard")) { System.out.print("Enter '+' for addition, '-' for substractions, '*' for multiplication, '/' for division, 'sin' for sin x, 'cos' for cos x, 'tan' for tan x:"); System.out.println("Enter Choice: "); choice = yurr.next(); switch (choice) { case "+": double x7, results7 = 0.0, number7=0.0; System.out.println("How many numbers do you want to add:"); x7 = yurr.nextDouble(); System.out.println("Enter " + x7 + " numbers:"); for ( i = 1.0; i <= x7; i++) { number7 = yurr.nextInt(); results7 = results7 + number7; } System.out.println("The result will be "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
