Page 1 of 1

nis lab you won't be creating images that are as complicated as the one in Figure 1 (such images take a great 1 of plann

Posted: Thu Jul 14, 2022 2:06 pm
by answerhappygod
Nis Lab You Won T Be Creating Images That Are As Complicated As The One In Figure 1 Such Images Take A Great 1 Of Plann 1
Nis Lab You Won T Be Creating Images That Are As Complicated As The One In Figure 1 Such Images Take A Great 1 Of Plann 1 (70.24 KiB) Viewed 23 times
Nis Lab You Won T Be Creating Images That Are As Complicated As The One In Figure 1 Such Images Take A Great 1 Of Plann 2
Nis Lab You Won T Be Creating Images That Are As Complicated As The One In Figure 1 Such Images Take A Great 1 Of Plann 2 (66.87 KiB) Viewed 23 times
Nis Lab You Won T Be Creating Images That Are As Complicated As The One In Figure 1 Such Images Take A Great 1 Of Plann 3
Nis Lab You Won T Be Creating Images That Are As Complicated As The One In Figure 1 Such Images Take A Great 1 Of Plann 3 (63.2 KiB) Viewed 23 times
nis lab you won't be creating images that are as complicated as the one in Figure 1 (such images take a great 1 of planning and practice). Instead, you'll begin by writing a program that generates a triangle, made up of racters chosen by user. See Figure 3 for the output that your program will generate. To complete this part of lab: Create a new java file. Type the text that is shown in Figure 2 into the editor panel of the new java file that you just created. Add/modify the comments accordingly, so that your name is listed as an author, and so that you include a description of the program. As always, be generous with using comments. Save the file as AsciiTriangle java in your lab5 folder. Compile the program and run it. Make sure that: the program outputs what you see in Figure 3. If you have typed any part of the code incorrectly (and introduced a syntax error, you'll have to fix the error, until your code is error-free). String eSCIICharacter = =⋯; Scanner keyboard = new Scanner(System.in): Figure 2: Java code to create triangle ASCII art image.
I. w-j CRASP exec: java Aseittriangle This program prints a sinple ASCII triangle. How tall should the triangle be? 7 what ASCII character should be used to draw the triangle? Figure 3: Sample output of the program in Figure 2. II. The for loop Another loop control structure, in addition to the while and do-while loops, is the for loop, which you've seen in lecture already. The for loop has a very similar functionality to the while loop, but the syntax is different. In this part of the lab, you'll recreate the triangle ASCII program that you wrote for the previous part of this lab, but you'll use a for loop instead of a while loop. To complete this part of the lab: 1. Create a new file, For LoopAsciiArt java inside of your lab5 folder. 2. Import Java's Scanner functionality; at the top of your file, write: import java. uti1. Scanner; 3. Write a main method, and inside of it, set up a Scanner that is listening to the keyboard, and print to the screen the following questions: How tall is the triangle? Use the Seanner's nextInt () method, to retrieve from the keyboard, the number input by the user, which you should save into a variable triangleHeight of type int. 4. To output the "percent" characters (\%), you'll need to use two for-loops, an outer loop and an inner loop: a. The outer loop should have an iterator variable, row, set to 0 in the initialization step. The update step should be row+t, and the loop should iterate as long as row <- triangleHe ight. Therefore, this loop will perform as many iterations as the number that was input by the user. The outer for loop should look like the following: for (int row = 0, row k= triangleHeight; rowitt) t 1/ body of outer for 100p 1 b. Inside of the body of the outer for loop, write ANOTHER for loop. The idea is, that at row x of the triangle, you print x asterisks. The inner loop uses the value of the row variable, to determine how many columns of asterisks to print. The println is needed to generate a new line after each row of the triangle is printed. your inner for loop (the loop INSIDE the body of the outer loop), should be: for (int column =0 i column < row cotunn+4 t
5. Complete the program by making sure that the main and class sections are comrectly closed using the closing curly brackets. Compile and run your peogram. Make sure that your program reproduces the output that is sbown in Figures 4. *.jGASP exec: yava ForLoophsef1Nrt How tall is the triangle? x ver 10x Figure 4: Sample output of the program ForLoopdsciiArt,jave III. The for loop; decrementing In this part of the lab, you'll again print a triangle, but this time, an upside-down triangle. See Figure 5 , for example output. The code for this program is nearly idenfical to the program for printing a right-side-up triangle. The only difference is that the for loop decrements. To complete this part of the lab: 1. Using jGRASP, create a new file, UpsideDowntriangle,jave, inside of your lab5 folder. 2. Import the Scanner functionality, at the top of your java file. Write a main method, and inside of it, create a Scanner that is listening to the keyboard. 3. Print to the screen the following questions: How tall is the upside-down triangle? 4. Use the Seanner's next Int (1), method, to retrieve from the keyboard, the number input by the user, which you should save into a variable triangleHeight of type int. 5. To output the percent characters (\%), you'll again need two for-loops, an outer loop and an inner loop. The "first" row of the triangle, however, should have as many columns as the aumber that is placed into the variable triangleHeight. Then, each soccessive row should have one fewer asterisk. a. The outer loop should have an iterator variable, row, set to triangleHe ight in the initialization step. The update step should be rown −, and the loop should iterate as long as row >0. Therefore, this loop will perform as many iterations as the number that was input by the user, but it is different. than the for loop that you wrote for part I of this lab, because the "fint" row has the most columns of asterisks, and each successive row has one fewer. b. Inside of the body of the outer for loop, write ANOTHER for loop, which is ideatical to the inner for loop that you wrote for part II of this lab, 6. Compile and rua your program. Make sure that your program can reprodoce the output in Figure 5 . tage 4 ats