Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a java program Declare Variables: Inside the main method, start by declaring the variables you will use: continueRunning ( boolean ) to control the
Create a java program
Declare Variables:
Inside the main method, start by declaring the variables you will use:
continueRunning boolean to control the main loop.
option int to store user's menu choice.
studentPhoneNum, FormattedPhoneNum String for handling phone numbers.
fname, lname String for the student's first and last name.
courseName String and studentScore double for course details.
Implement the Main Loop:
Use a while loop to keep the program running until the user decides to exit.
Display a menu with options for:
Adding or viewing a student's course and grade.
Formatting and displaying the student's name.
Entering and formatting a students phone number.
Exiting the program and display student Information.
Use Scanner to read the users choice and implement the functionality based on the choice.
Implement Menu Options:
Option : Student Course and Grade
Prompt the user to enter the course name and the student score.
Display the course and score.
Option : Format Student Names
Ask for the student's first and last namesindividually
Convert the names to uppercase and display them.
Display the initials of the student.
Option : Enter Student Phone Number
Prompt for a digit phone number.
Format it as XXXXXXXXXX and display.
Option : Exit
Display all collected information.
Thank the user and prepare to exit the loop.
Error Handling for Menu Selection:
Add an error handling mechanism to the menu selection process:
Inside your main loop, after processing valid options with if and else if statements, use an else statement
to handle any input that does not match a defined option.
Display an error message: Invalid Option Please see the Sample Run
Also, In option and option we might need the buffer clearing, use inputnextLine inside the if else
if statement.
Loop Control:
After executing any of the options, ask the user if they want to continue.
If the user types No set continueRunning to false to exit the loop.
Otherwise, continue with the next iteration.
The loop Control should work with upper and lower case for Yes and No
Documentation and Comments:
Add comments to your code to explain the purpose of each part and how it works.
use this example
import java.util.Scanner;
public class UsingDifferentLoopsExample
public static void mainString args
declare and initialize variables
User will enter the grocery items
int items;
user will enter total number of groceries to purchase
int groceryQuantity;
for the user to select yes or no
String select;
to calculate the total of grocery items purchased
int sum;
boolean to get out of the loop
boolean choice true;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started