This lab is for practicing the nested for loops and switch statement.
Use the following Coding Guidelines:
At the beginning of each programming assignment you must have a comment block with the following information:
/*---------------------------------------------------------------------------
// AUTHOR: (Put your name here)
// FILENAME: Lab6.java
// SPECIFICATION: This program is for practicing nested loops.
// It prints out a certain size of right triangle of stars
// INSTRUCTIONS: Read the following code skeleton and add your own code
// according to the comments. Ask your TA or your class-
// mates for help and/or clarification. When you see
// //--> that is where you need to add code.
// LAB LETTER: (Put your lab letter)
//-------------------------------------------------------------------------*/
Create a class called Lab6. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab6.java. Hints Please replace //--> with the correct program to finish the task according to the corresponding comment. Please replace ??? with the correct program to enable the program to run as required.
/*---------------------------------------------------------------------------
// AUTHOR: (Put your name here)
// FILENAME: Lab6.java
// SPECIFICATION: This program is for practicing nested loops.
// It prints out a certain size of right triangle of stars
// INSTRUCTIONS: Read the following code skeleton and add your own code
// according to the comments. Ask your TA or your class-
// mates for help and/or clarification. When you see
// //--> that is where you need to add code.
// LAB LETTER: (Put your lab letter)
//-------------------------------------------------------------------------*/
//import anything you need
//-->
//declare the class Lab6
//-->
//declare the main method
//-->
// Declare Constant integers Trangle = 1, QUIT = 2
// Define scan object of the type Scanner class
//-->
// Create an integer variable named choice.
//-->
// Create a do-while loop that exits only when the user chooses quit (choice = QUIT)
// Have the do-statement here
??
{
// Print the following options:
// "This proram does the following:"
//-->
// "1. Print a Triangle:"
//-->
// "2. Quit"
//-->
// Read the value the user enters and store it in an integer variable
//-->
// Create a switch statement withas input for the 2 cases
switch(???)
{
case Trangle:
//define an int variable
//-->
// Print "Please input the triangle height:"
//-->
//scan the next integer and assign it to
//-->
// First for loop
// 1st ??? --> define an int variable and initialize it to 1
// 2nd ??? --> check if is less than equal to
// 3rd ??? --> increment variable by 1
for (???;???;???)
{
// Second for loop
// Let the inner loop run from j=1 up to and including i
for (???)
{
// The inner loop prints the single star
//-->
}
// Start a new line
//-->
}
// First for loop
// 1st ??? --> define an int variable and initialize it to size-1
// 2nd ??? --> check if is greater than or equal to 1
// 3rd ??? --> subtract variable by 1
for(???;???;???)
{
// Second for loop
// Let the inner loop run from j=0 up to i
for(???;???;???)
{
// The inner loop prints the single star
//-->
}
// start a new line
//-->
}
//terminate this case using break
//-->
case QUIT:
// Print "You choose to quit"
//-->
//terminate this case
//-->
default:
// Print "Please choose again"
//-->
}
}while(???);
//Remember to close the braces for the main method and class.
//-->
//-->
This proram does the following:
1. Print a Triangle:
2. Quit
1
Please input the triangle height:5
*
**
***
****
*****
****
***
**
*
This proram does the following:
1. Print a Triangle:
2. Quit
3
Please choose again
This proram does the following:
1. Print a Triangle:
2. Quit
1
Please input the triangle height:4
*
**
***
****
***
**
*
This proram does the following:
1. Print a Triangle:
2. Quit
2
You choose to quit