Question: What this Lab Is About: Familiarization with for loop Use of nested loops Menu driven applications Use the following Coding Guidelines: When declaring a variable,








What this Lab Is About: Familiarization with for loop Use of nested loops Menu driven applications Use the following Coding Guidelines: When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem Description: Displaying menu options and performing operations based on user choice For this Lab your program must perform three different operations based on a user's input. To do this, you must show the user the menu, ask the user for their choice, perform the appropriate computation, and then repeat until the user exits. The menu is as follows: Please choose from following menu: 1) Print all integer numbers between two given integers 2) Display a right triangular pattern of stars. 3) Quit. Step 1: Getting Started Create a class called Lab5. Use the same setup for setting up your class and main method as you did in previous labs and assignments. Be sure to name your file Lab5.java Assignment Documentation: At the beginning of each programming assignment you must have a comment block with the following information // AUTHOR:your name //FILENAME:title of the source file SPECIFICATION: description of the program // FOR: CSE 110- Lab #5 TIME SPENT: how long it took you to complete the assignment Step 2: Beginning the loop and declaring variables The first part of the problem is to show the user the menu, collect the user's menu choice as an input, and repeat it until the user selects the exit option. For this, we need to declare a variable named choice to store the user choice. int choice = 0; Next, we must select the appropriate loop for the main body of the program. In this case, since we know that the program should execute at least once, a do-while loop is most appropriate. Inside the loop, print the menu using System.out.println statements and then request the menu option from the user. A skeleton do-while loop follows. Remember to add the Scanner statement that requests the choice from the user. dot //Please choose from following menu: // 1) Print integer numbers between two given integers. // 2) Display a right triangular pattern of stars /3) Quit. // Use scanner to collect user input while(/*termination condition/D Remember every loop should have a termination condition. Here the loop should run until user chooses option 4. So the termination condition would be (choice != 3) Step 3: Performing operations Based on the choice entered by the user, we need to do some arithmetic operations. Inside the do-while loop, but after the menu, initialize a switch-case statement to perform the operations. The switch-case statement hinges on the choice variable, which should now have an integer value. An example switch-case statement follows switch(choice) ( case 1:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
