Question

LANGUAGE IS JAVA CALCULATOR USING SCIENTIFIC/STANDARD MODE ERRORS: ADDITION AND DIVISION NOT WORKING FOR EITHER CALCULATOR...

LANGUAGE IS JAVA

CALCULATOR USING SCIENTIFIC/STANDARD MODE

ERRORS:

ADDITION AND DIVISION NOT WORKING FOR EITHER CALCULATOR

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;
String answer = "Y";
while (answer.equals("Y")) {

System.out.println("Enter the calculator mode: Standard/Scientific?");
mode = yurr.next();

if(mode.equals("Scientific")) {


System.out.print("Enter '+' for addition, '-' for subtractions, '*' 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 results = 0.0, number= 0.0;
int x;
System.out.println("How many numbers do you want to add?");
x = yurr.nextInt();
System.out.println("Enter " + x + " numbers");
for ( i = 1.0; i <= x; i++) {
number = yurr.nextDouble();
results = results + number;
}
System.out.println("Result: " + results);
break;


case "-":
double results1 = 0.0, number1 = 0.0;
int x1;
System.out.println("How many numbers do you want to subtract?");
x1 = yurr.nextInt();
System.out.println("Enter " + x1 + " numbers");
for ( i = 1.0; i <= x1 ; i++) {
number1 = yurr.nextDouble();
results1 = results1 - number1;

}
System.out.println("Result: " + results1);
break;


case "*":
double results2 = 1.0, number2=0.0;
int x2;
System.out.println("How many numbers do you want to multiply?");
x2 = yurr.nextInt();
System.out.println("Enter " + x2 + " numbers");
for ( i = 1.0; i <= x2; i++) {
number2 = yurr.nextDouble();
results2 = results2 * number2;
}
System.out.println("Result: "+ results2);
break;


case "/":
double results3 = 1.0, number3 = 1.0;
int x3;
System.out.println("How many numbers do you want to divide?");
x3 = yurr.nextInt();
System.out.println("Enter " + x3 + " numbers");
for ( i = 1.0; i <= x3 ; i++) {
number3 = yurr.nextDouble();
results3 = results3 / number3;
}
System.out.println("Result: " + results3);
break;


case "sin":
double radian;
System.out.println("Enter a number in radians to find the sine");
radian = yurr.nextDouble();
System.out.println("Result: " + Math.sin(radian));
break;


case "cos":
double radian1;
System.out.println("Enter a number in radians to find the cosine");
radian1 = yurr.nextDouble();
System.out.println("Result: " + Math.cos(radian1));
break;


case "tan":
double radian2;
System.out.println("Enter a number in radians to find the tangent");
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.println("The calculator will operate in standard mode.");

System.out.print("Enter '+' for addition, '-' for subtractions, '*' 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 results7 = 0.0, number7=0.0;
int x7;
System.out.println("How many numbers do you want to add?");
x7 = yurr.nextInt();
System.out.println("Enter " + x7 + " numbers");
for ( i = 1.0; i <= x7; i++) {
number7 = yurr.nextDouble();
results7 += number7;
}
System.out.println("Result: " + results7);
break;


case "-":
double results4 = 0.0, number4=0.0;
int x4;
System.out.println("How many numbers do you want to subtract?");
x4 = yurr.nextInt();
System.out.println("Enter " + x4 + " numbers");
for ( i = 1.0; i <= x4; i++) {
number4 = yurr.nextDouble();
results4 -= number4;
}
System.out.println("Result: " + results4);
break;


case "*":
double results5 = 1.0, number5=0.0;
int x5;
System.out.println("How many numbers do you want to multiply?");
x5 = yurr.nextInt();
System.out.println("Enter " + x5 + " numbers");
for ( i = 1.0; i <= x5; i++) {
number5 = yurr.nextDouble();
results5 *= number5;
}
System.out.println("Result: " + results5);
break;


case "/":
double results6 = 1.0, number6=1.0;
int x6;
System.out.println("How many numbers do you want to divide?");
x6 = yurr.nextInt();
System.out.println("Enter " + x6 + " numbers");
for ( i = 1.0; i <= x6 - 1.0; i++) {
number6 = yurr.nextDouble();
results6 /= number6;
}
System.out.println("Result: " + results6);
break;

}
}
else {
System.out.println("Invalid operation entered");
}
System.out.println("Do you want to start over? (Y/N)");
answer = yurr.next();


}
System.out.println("Goodbye.");
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
String answer = "Y";
while (answer.equals("Y")) {

System.out.println("Enter the calculator mode: Standard/Scientific?");
mode = yurr.next();

if(mode.equals("Scientific")) {


System.out.print("Enter '+' for addition, '-' for subtractions, '*' 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 results = 0.0, number= 0.0;
int x;
System.out.println("How many numbers do you want to add?");
x = yurr.nextInt();
System.out.println("Enter " + x + " numbers");
for ( i = 1.0; i <= x; i++) {
number = yurr.nextDouble();
results = results + number;
}
System.out.println("Result: " + results);
break;


case "-":
double results1 = 0.0, number1 = 0.0;
int x1;
System.out.println("How many numbers do you want to subtract?");
x1 = yurr.nextInt();
System.out.println("Enter " + x1 + " numbers");
for ( i = 1.0; i <= x1 ; i++) {
number1 = yurr.nextDouble();
results1 = results1 - number1;

}
System.out.println("Result: " + results1);
break;


case "*":
double results2 = 1.0, number2=0.0;
int x2;
System.out.println("How many numbers do you want to multiply?");
x2 = yurr.nextInt();
System.out.println("Enter " + x2 + " numbers");
for ( i = 1.0; i <= x2; i++) {
number2 = yurr.nextDouble();
results2 = results2 * number2;
}
System.out.println("Result: "+ results2);
break;


case "/":
double results3 = 1.0, number3 = 1.0;
int x3;
System.out.println("How many numbers do you want to divide?");
x3 = yurr.nextInt();
System.out.println("Enter " + x3 + " numbers");
number3 = yurr.nextDouble();
results3=results3*number3;
for ( i = 1.0; i <= x3-1.0 ; i++) {
number3 = yurr.nextDouble();
results3 = results3 / number3;
}
System.out.println("Result: " + results3);
break;


case "sin":
double radian;
System.out.println("Enter a number in radians to find the sine");
radian = yurr.nextDouble();
System.out.println("Result: " + Math.sin(radian));
break;


case "cos":
double radian1;
System.out.println("Enter a number in radians to find the cosine");
radian1 = yurr.nextDouble();
System.out.println("Result: " + Math.cos(radian1));
break;


case "tan":
double radian2;
System.out.println("Enter a number in radians to find the tangent");
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.println("The calculator will operate in standard mode.");

System.out.print("Enter '+' for addition, '-' for subtractions, '*' 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 results7=0.0, number7=0.0;
int x7;
System.out.println("How many numbers do you want to add?");
x7 = yurr.nextInt();
System.out.println("Enter " + x7 + " numbers");
for ( i = 1; i <= x7; i++) {
number7 = yurr.nextDouble();
results7 += number7;
}
System.out.println("Result: " + results7);
break;


case "-":
double results4 = 0.0, number4=0.0;
int x4;
System.out.println("How many numbers do you want to subtract?");
x4 = yurr.nextInt();
System.out.println("Enter " + x4 + " numbers");
for ( i = 1.0; i <= x4; i++) {
number4 = yurr.nextDouble();
results4 -= number4;
}
System.out.println("Result: " + results4);
break;


case "*":
double results5 = 1.0, number5=0.0;
int x5;
System.out.println("How many numbers do you want to multiply?");
x5 = yurr.nextInt();
System.out.println("Enter " + x5 + " numbers");
for ( i = 1.0; i <= x5; i++) {
number5 = yurr.nextDouble();
results5 *= number5;
}
System.out.println("Result: " + results5);
break;


case "/":
double results6 = 1.0, number6=1.0;
int x6;
System.out.println("How many numbers do you want to divide?");
x6 = yurr.nextInt();
System.out.println("Enter " + x6 + " numbers");
number6 = yurr.nextDouble();
results6=results6*number6;
for ( i = 1.0; i <= x6 - 1.0; i++) {
number6 = yurr.nextDouble();
results6 /= number6;
}
System.out.println("Result: " + results6);
break;

}
}
else {
System.out.println("Invalid operation entered");
}
System.out.println("Do you want to start over? (Y/N)");
answer = yurr.next();


}
System.out.println("Goodbye.");
}
}

CORRECTION:

ADDITION IS WORKING FINE

IN DIVISION THE FIRST INPUT NUMBER SHOULD BE THE NUMERATOR AND REST ARE DENOMINATORS, SO FIRST INPUT SHOULD BE MULTIPLIED WITH THE RESULT . THANK YOU

Add a comment
Know the answer?
Add Answer to:
LANGUAGE IS JAVA CALCULATOR USING SCIENTIFIC/STANDARD MODE ERRORS: ADDITION AND DIVISION NOT WORKING FOR EITHER CALCULATOR...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Debug the following java code so that it will have given out put at the bottom....

    Debug the following java code so that it will have given out put at the bottom. Make sure to fix all syntax and logical errors. import java.util.Scanner; public class Graphs { // draws 5 histograms public void drawHistograms() Scanner input = new Scanner( System.in ); int number1 = 0; // first number int number2 = 0; // second number int number3 = 0; // third number int number4 = 0; // fourth number int number5 = 0; // fifth number...

  • IN JAVA: Write a program that displays a menu as shown in the sample run. You...

    IN JAVA: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1 is...

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

  • Eclipse Java Oxygen Question 11 pts A compile-time error occurs when Group of answer choices c....

    Eclipse Java Oxygen Question 11 pts A compile-time error occurs when Group of answer choices c. there’s a syntax error in a Java statement a. the Java compiler can’t be located b. bytecodes can’t be interpreted properly c. there’s a syntax error in a Java statement Flag this Question Question 21 pts An error that lets the application run but produces the wrong results is known as a Group of answer choices d. syntax error c. logic error a. runtime...

  • Here is the code I made, but the test case is not working, it goes wrong...

    Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) {        int array[16];        int i = 0;        for (int counter = 0; counter < 16; counter++)        {               array[counter] = 0;        }        while (number > 0)        {...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • Calculator Project

    AssignmentYou will be designing a calculator complete with user interface to take input from the user, process a response, and produce the output.Step 1: Present a menuFirst thing you should do is present a menu to the user when your program is first ran. Make sure that the operations match the numbers presented below, otherwise the graders won't be able to grade your program.1. Cartesian distance 2. Vector x matrix 3. Normalize 4. Quit Enter command:You will present the menu and wait for the user to input their...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT