March 26 Assignment

Preface

Tools that can be used to log into cs.bridgewater.edu and instructions on how to clone our shared GitHub repository and  can be found in the March 22 assignment.

Instructions

Please log into cs.bridgewater.edu.  Navigate to the csci101/hw/mar26 directory in your git repository.  Write a program in a file named Practice.java that satisfies the following program specifications.

Program Specifications

Write a program that behaves exactly like the March 24th assignment, but this time use a switch statement instead of an if-else-if chain.  In addition, create and call a function named printMenu to print the menu to the screen.  Below is a copy of the March 24th assignment.

The program should repeatedly (until the user enters 6) print to the screen a menu that reads as follows

1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus
6. Quit
Please enter an option:

When the user presses 1, 2, 3, 4, or 5, the program asks the user to enter two values for the two operands.  The program then performs the respective operation (based on the option the user chose) on the operands and prints to the screen an equation that includes the operands the operator and equals symbol and the result of the operation on the operands.

If the user enters option 6, the program terminates.

Sample output

1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus 
6. Quit
Please enter an option:
1
Please enter the first operand
7
Please enter the second operand
4
Result: 7 + 4 = 11

1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus 
6. Quit
Please enter an option:
6

© 2021 – 2024, Eric. All rights reserved.