Question: 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

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 users 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 your choice from following menu: 1) Print through 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. Assignments 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: your own 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 and repeat the menu until the user selects the exit option. For this, we need to declare a variable choice to store the user choice. int choice; //initialize do-while loop 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. do{ //Please choose your choice from following menu //1) Print through all integer numbers between two given integers. //2) Display a pattern right triangle of stars. //3) Quit. } while(/* termination condition*/); Remember every loop should have a termination condition. Here the loop should run until user chooses option 3. So the termination condition would be (choice != 3) Step 3: Performing arithmetic operations Based on the choice entered by the user, we need to do some 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: break; case 2: break; case 3: break; default: break; } Step 4: CASE 1 Print through all integer numbers between two given integers. /* Code to be done inside CASE 1 statement */ If the user chooses option one, they wish to print all integer numbers between two given integers. For this task, we need: start, end, the integers entered by the user. int start=0, end=0; Ask the user to enter the first number (start) and second number (end) using System.out.println and a use the Scanner object to scan the value that the user enters and assign it to start and end respectively. To perform the operation, we need an intermediate variable that goes from start to end in a loop. For that, declare an index variable. int i; Begin the for loop using loop variable i. A for loop has three parts 1. Initialization (i = start) 2. Termination condition(i <= end //until i is less than end ) 3. Loop update (i++ //increment the value of i after each iteration): for(i= start; i<=end; i++) { // use System.out.println to print numbers between start and end } Step 5: CASE 2 Nested For-Loops: Ask the user to input the height of the triangle. Write a nested for-loop to print out a right triangle of stars. Here is a pseudo-code (algorithm) to help you to print the triangle of stars. Declare an int variable height. int height Ask the user to enter height using System.out.println and a use the Scanner object to scan the value that the user enters and assign it to height. Here we need two index variables, one for the outer loop and the other for the inner loop. int i,j;(ignore declaring i if you have already did it for the previous case , i.e. case 1) The outer loop has to repeat height times and the inner loop has to print the stars. After executing inner loop print a new line so that the next group of stars will be printed on a new line. Outer loop will look like this for(i = 1; i <= height; i++){ //Inner Loop //Print } The inner loop prints one star for the first iteration, two stars for the second iteration and so on until you print the last line which has height stars. for(j = 1; j <= i; j++){ //print * } Step 6: Display the output You should display the answer of the CASE conditions as mentioned and repeat the menu operations. Sample Output Below is an example of what your output should roughly look like when this lab is completed. Text in bold represents user input. Please choose from following menu 1. Print through all integer numbers between two given integers. 2. Generate a right triangular pattern of stars. 3. Quit. 1 Enter the start number 1 Enter the end number 4 1 2 3 4 Please choose from following menu 1. Print through all integer numbers between two given integers. 2. Generate a right triangular pattern of stars. 3. Quit. 2 Enter the height 5 * ** *** **** ***** Please choose from following menu 1. Print through all integer numbers between two given integers. 2. Generate a right triangular pattern of stars. 3. Quit.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!