Java Lab Activity: Math App with Loops
(Terminal Version)
Engr. Jamie Eduardo Rosal, MSCpE
Objective
By the end of this activity, students will:
1. Apply loops to repeatedly run user-selected computations.
2. Practice using the Scanner class for input.
3. Strengthen decision-making using if-else or switch-case statements.
Activity Description
You will create a Math App in Java that runs entirely in the terminal. The program should:
1. Display a menu with 8 different mathematical computations.
2. Accept user input to select which computation to perform.
3. Perform the computation based on user input.
4. Display the result.
5. Ask the user if they want to perform another computation.
○ If Yes, show the menu again.
○ If No, terminate the program with a thank-you message.
Step 1 – Menu Example
The menu might look like this (you can choose your own 8 computations):
=== Math App Menu ===
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Factorial of a number
6. Power (x^y)
7. Sum of numbers 1 to N
8. Check if a number is prime
0. Exit
Step 2 – Example Flow
=== Math App Menu ===
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Factorial of a number
6. Power (x^y)
7. Sum of numbers 1 to N
8. Check if a number is prime
0. Exit
Enter your choice: 1
Enter first number: 10
Enter second number: 5
Result: 15
Do you want to perform another computation? (yes/no): yes
Then the menu displays again until the user types no or selects 0. Exit.
Step 3 – Core Requirements
● Must use a loop (e.g., while or do-while) to keep showing the menu.
● Must use if-else or switch-case to handle menu choices.
● Must implement 8 computations (programmer’s choice, examples given above).
● Must handle invalid inputs gracefully (e.g., divide by zero, negative factorial, etc.).
Submission Instructions
1. Save your program as [Link].
Upload your code to GitHub in a repository named:
MathApp_LastName_FirstName
2. Include at least two screenshots of test runs (one with normal inputs, one showing error
handling or edge cases).
3. Submit the GitHub repository link to your instructor.