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

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 01:30
Jason works as an accountant in a department store. he needs to keep a daily record of all the invoices issued by the store. which file naming convention would him the most? a)give the file a unique name b)name the file in yymmdd format c)use descriptive name while naming the files d)use capital letters while naming the file
Answers: 3
question
Computers and Technology, 23.06.2019 14:00
Select the correct answer. andre was recently hired by an organization to check for system vulnerabilities. he is supposed to exploit these vulnerabilities and create a report on the extent of damage to which the system was susceptible. what position does andre hold in this organization? a. information security analyst b. information assurance manager c. penetration tester d. network security engineer e. chief information security officer
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 3
question
Computers and Technology, 23.06.2019 23:40
Which of the following calculates the total from the adjacent cell through the first nonnumeric cell by default, using the sum function in its formula? -average -autosum -counta -max
Answers: 1
You know the right answer?
In this lab, you complete a partially written java program that includes a method that returns a val...
Questions
question
Mathematics, 04.07.2019 16:00
question
History, 04.07.2019 16:00
question
Mathematics, 04.07.2019 16:00
Questions on the website: 13722367