Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description: Displaying menu options and performing operations base&sh usprecheiesu Colleges For this Lab your program must perform two different operations based on a user's

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Problem Description: Displaying menu options and performing operations base&sh usprecheiesu Colleges 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 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 ASU Home My ASU Colleges & 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. do{ //Please choose from following menu: // 1) Print all integer numbers between two given integers. // 2) Display a right triangular pattern of stars. // 3) Quit. // Use scanner to collect user input } 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 ASU Home My ASU Colleges 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: Step 5: CASE 2 - Nested for Loops ASU Home My ASU College This will print a triangle made of stars (*). 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. get height of triangle from user initialize numberOfStars to o for rowCount = 1 to height numStars += 1 for starCount = 1 to numStars print a star print a newline character You will need to declare variables for the height, and to keep count of the rows and to keep track of the count of stars in each row. You will need to ask the user to enter height using System.out.println and a use a Scanner object to scan the value that the user enters and assign it to height. The outer loop has to repeat height times (once for each row), and the inner loop has to print the stars for each row. After executing inner loop print a new line so that the next group of stars will be printed on a new line. Your outer loop will look like this: for (int rowCount = 1; rowCount 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 1) Print all integer numbers between two given integers. 2) Generate a right triangular pattern of stars. 3) Quit. 1 Enton tho ctant numhan. 1 Sample Run 1: ASU Home My ASU College Please choose from following menu 1) Print all integer numbers between two given integers. 2) Generate a right triangular pattern of stars. 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 between two given integers. 2) Generate a right triangular pattern of stars. 3) Quit. Enter the height: 5 Please choose from following menu 1) Print 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

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

Recommended Textbook for

More Books

Students also viewed these Databases questions