subject

In this lab, you complete a partially written java program that includes a method that returns a value. the program is a simple calculator that prompts the user for two numbers and an operator ( +, −, *, /,or% ). the two numbers and the operator are passed to the method where the appropriate arithmetic operation is performed. the result is then returned to the main() method where the arithmetic operation and result are displayed. for example, if the user enters 3, 4, and *, the following is displayed:
3.00 * 4.00 = 12.00
// 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 (+*,/,%): ");

// 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.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 04:30, kkeith121p6ujlt
Eye injuries usually occur as a result of all of the following things, except: a) proper machine operation b) battery explosion c) falling or flying debris d) electric welding arc
Answers: 2
image
Computers and Technology, 25.06.2019 03:00, reearamrup27
Match the categories in the first column with examples in the second column. 1. good for watching movies 2. maximum power with small size 3. older style mobile devices that may or may not have internet connectivity tablet computer a.)pda b.)smart phone c.)tablet computer
Answers: 1
image
Computers and Technology, 25.06.2019 06:20, joe7977
If you want to change the speed of a layer's horizontal scrolling, what should you change? a. the x coefficient b. the y coefficient c. the virtual width d. the order of the game's layers select the best answer from the choices provided
Answers: 2
image
Computers and Technology, 25.06.2019 08:10, andrewmena05
Spreadsheet software is more powerful than financial planning software. - true or false
Answers: 2
You know the right answer?
In this lab, you complete a partially written java program that includes a method that returns a val...

Questions in other subjects:

Konu
Mathematics, 28.01.2021 19:20
Konu
History, 28.01.2021 19:20
Konu
Mathematics, 28.01.2021 19:20