Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

languagejava Problem Description: Displaying menu options and performing operations based on user choice For this Lab your program must perform two different operations based on

languagejava image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Problem Description: Displaying menu options and performing operations based on user choice For this Lab your program must perform two different operations based on a user's input. To do this, you must show the user a menu, ask the user for their choice, perform the appropriate computation, and then repeat until the user chooses to exit. The menu is as follows: Please choose from following menu: 1) Print all integer numbers betwee: 2) Display a right triangular patte: 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: Assignment Documentation: At the beginning of each programming assignment you must have a comment block with the following information: 1 - -- ---- --- - - // AUTHOR: your name // FILENAME: title of the source fi // SPECIFICATION: description of th // FOR: CSE 110- Lab #5 // TIME SPENT: how long it took you --- ---- - - --- ------ --- -- - 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 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 from following 11 1) Print all integer numbers 11 2) Display a right triangula 1/ 3) Quit. // Use scanner to collect user } while(/*condition*/); Remember every loop must have a condition. Here the loop should run until user chooses option 3. So the condition would be (choice != 3) Step 3: Performing operations Step 3: Performing 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 Integers Step 4: CASE 1 - Print Integers If the user chooses option 1, they wish to print out a list of the integers from start to end. Thus, we must request these numbers from the user. First, we declare two new integers, one for start, one for end. int start = 0, end = 0; Ask the user to enter a starting number (start) using System.out.println and then use a Scanner object to get the value. Then do this again for end. To perform the operation, we need another variable that will count from start to end in a loop. We will add this value to count each time the body of the loop executes. For that, declare and initialize a variable named count. int count; Begin a for loop using count with a condition that will cause it to repeat until its value is Begin a for loop using count with a condition that will cause it to repeat until its value is greater than end. Inside the loop we will print out the current value of count. for (count = start; count Sample Output Below is an example of what your output should roughly look like when this lab is completed, with user input in red. Sample Run 1: Please choose from following menu Assignment Documentation: At the beginning of each programming assignment you must have a comment block with the following information: 1 - -- ---- ---- - // AUTHOR: your name // FILENAME: title of the source fi // SPECIFICATION: description of th // FOR: CSE 110- Lab #5 // TIME SPENT: how long it took you --- ---- - - --- ------ --- -- - 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 The inner loop prints the correct number of stars on each line (row) - 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. Notice that the number of stars to print on a row is the same as the rowCount for that row - in other words, when rowCount is 1, we will print 1 star, and when rowCount is 2 we will print 2 stars, and so on. Your outer loop will look like this: for(int starCount = 1; starCount 1/ Sample Output Below is an example of what your output should roughly look like when this lab is completed, with user input in red. Sample Run 1: Sample Run 1: Please choose from following menu 1) Print all integer numbers betwee 2) Generate a right triangular patt 3) Quit. Enter the start number: 1 Enter the end number: 4 1 2 3 4 Please choose from following menu 1) Print all integer numbers betwee: 2) Generate a right triangular patt 3) Quit. Enter the height: 5 ** * * * * * * * ** ** * * Please choose from following menu 1) Print all integer numbers betwee 2 Generate a right triananlar nat+ Please choose from following menu 1) Print all integer numbers betwee 2) Generate a right triangular patt 3) Quit. Last Step: Submit your work by the end of lab by following the instructions below: 1. Upload and submit your Lab5.java file here. 2. Have a TA verify that you submitted the correct file, and that your submission meets all requirements described in the rubric below. Grading Rubric Criterion Points Possible 5 Lab Attendance Student's Submission ... includes a file named Lab5.java with a class named Lab5 uses at least 3 loops

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago