Question: Java simple calculator. The errors are: could not find or load main class, and illegal start of expressions for the if statement, and the if
Java simple calculator. The errors are: could not find or load main class, and illegal start of expressions for the if statement, and the if else statements. Can you steer me in the right direction, and explain my errors? In this lab the only code I wrote is the //call, and the //write portions. the rest was given.
// Calculator.java - This program performs arithmetic, ( +. -, *. /, % ) on two numbers // Input: Interactive. // Output: Result of arithmetic operation
import java.util.Scanner;
public class Calculator { public static void main(String args[]) { double numberOne, numberTwo; String numberOneString, numberTwoString; String operation; double result; Scanner input = new Scanner(System.in); System.out.println("Enter the first number: "); numberOneString = input.nextLine(); numberOne = Double.parseDouble(numberOneString); System.out.println("Enter the second number: "); numberTwoString = input.nextLine(); numberTwo = Double.parseDouble(numberTwoString); System.out.println("Enter an operator (+.-.*,/,%): "); operation = input.nextLine(); // Call performOperation method here result = performOperation(numberOne, numberTwo, operation);
System.out.format("%.2f",numberOne); System.out.print(" " + operation + " "); System.out.format("%.2f", numberTwo); System.out.print(" = "); System.out.format("%.2f", result); System.exit(0);
} // End of main() method. // Write performOperation method here. private static double performOperation(double num1, double num2, string operation) { if(operation == (+)) { result = num1 + num2; } else if(operation == (-)) { result = num1 - num2; } else if(operation == (*)) { result = num1 * num2; } else if(operation == (/)) { result = num1 / num2; } return result; } } // End of Calculator class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
