COP3502 Lab 01: One-Run Calculator Solved

25.00 $ 12.50 $

Category:

Description

 

Overview

In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using a scanner object. The program will then display the result of the operation and exit. The project is designed to give students an opportunity to practice input, output, selection, and basic operators via a simple project.

 

Specification

 

When the program starts it should prompt the user to enter an operand and read a double precision floating point number as follows:

 

Enter first operand: 89.1

Enter second operand: 42

 

Once the two operands have been read and stored, the program should display a menu as follows:

 

Calculator Menu

—————

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division

 

…and then display a menu and accept user input (we recommend an integer type for the input):

 

Which operation do you want to perform? 1

 

If a valid operation is selected, the program should print the result and exit:

 

The result of the operation is 131.1. Goodbye!

 

If the input is an invalid integer, it should print this error message and exit:

 

Error: Invalid selection! Terminating program.

Submissions

NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission!

 

File:                 Calculator.java

Method:           Submit on ZyLabs

 

Do not submit any other files!

 

Sample Output

 

Example #1



Enter first operand: 2.25

Enter second operand: -1.5

 

Calculator Menu

—————

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division

Which operation do you want to perform? 4

The result of the operation is -1.5. Goodbye!

 

Example #2



Enter first operand: 30.9

Enter second operand: 86.75

 

Calculator Menu

—————

  1. Addition
  2. Subtraction
  3. Multiplication
  4. Division

Which operation do you want to perform? 100

 

Error: Invalid selection! Terminating program.