Instructions
Please log into cs.bridgewater.edu. Navigate to the csci101/hw/mar29
directory in your git repository. Write a program in a file named Practice.java
that satisfies the following program specifications. When finished, push your code to GitHub.
Program Specifications
The program should consist of 7 functions as described below.
static void printMenu()
The printMenu function prints to the screen, the following menu.
add subtract multiply divide modulus quit Please type one of the above commands:
static double add(double operand1, double operand2)
The add function computes the sum of the two parameters and returns the result.
static double subtract(double operand1, double operand2)
The subtract function computes the difference of the two parameters and returns the result.
static double multiply(double operand1, double operand2)
The multiply function computes the product of the two parameters and returns the result.
static double divide(double operand1, double operand2)
The divide function computes the division of the two parameters and returns the result.
static int modulus(double operand1, double operand2)
The modulus function uses the modulus operator and returns the remainder when the first operand is divided by the second.
public static void main(String[] args)
The main function should repeatedly (until the user enters quit) do the following:
- print to the screen the menu by calling
printMenu()
- read in the user’s choice as a string
- ask the user for two decimal operands
- read in the operand values as decimal numbers
- use a switch statement on the user’s choice (string)
- inside each case call the appropriate function (add, subtract, etc.).
- If the user types quit, the program terminates.
- If the user types an invalid command, the program prints to the screen invalid command.
Sample Output
add subtract multiply divide modulus quit Please type one of the above commands: add Please enter the first operand 7 Please enter the second operand 4 Result: 7 + 4 = 11 add subtract multiply divide modulus quit Please type one of the above commands: quit
© 2021 – 2024, Eric. All rights reserved.