The result is as follows:
![]() |
This lab will help you understand the array and for-loops better.
Please, make sure that you have added the honor code statement at the top of your Java file:
/* THIS CODE IS MY OWN WORK, IT WAS WRITTEN WITHOUT CONSULTING CODE WRITTEN BY OTHER STUDENTS. _Your_Name_Here_ */ |
The deadline for completing this lab assignment is midnight, today.
mkdir ~/cs170/lab9 cp ~cs170002/share/lab9/* ~/cs170/lab9 cd ~/cs170/lab9 |
In this lab, we will use gedit and javac (not BlueJ !).
(Using BlueJ in this lab has resulted in freezing up of the workstation....)
|
UNIX>> javac DrawFlag.java UNIX>> java DrawFlag |
You should see this picture:
![]() |
The canvas is identified by the variable name pic.
gedit DrawFlag.java |
And look for this:
/* ========================================================== Try this: for ( col = 0; col < 400; col++ ) pixel[col][100] = YELLOW; ========================================================== */ |
Cut and paste the for-statement before that text:
/* ========================================================== Try this: for ( col = 0; col < 400; col++ ) pixel[col][100] = YELLOW; ========================================================== */ for ( col = 0; col < 400; col++ ) pixel[col][100] = YELLOW; |
UNIX>> javac DrawFlag.java UNIX>> java DrawFlag |
The canvas pic now contains this picture:
![]() |
/* ========================================================== TODO Part 1: .... ========================================================== */ |
Use the row variable to run through the value 0 to 299 and use the col variable to run through the value 0 to 399, and store the value YELLOW to the variable pixel[col][row].
javac DrawFlag.java java DrawFlag |
and if correct, you should see a red flag.
|
![]() |
You see that:
|
|
javac DrawFlag.java java DrawFlag |
and if correct, you should see a red background with a blue strip across the flag.
![]() |
You see that:
|
Find the equation for the other 2 lines and formulate a property for a coordinate (col, row) between the top and bottom lines.
Then write a nested for-loop to draw this diagonal.
javac DrawFlag.java java DrawFlag |
and if correct, you should see this:
![]() |
cd ~/cs170/lab9 /home/cs170002/turnin-lab DrawFlag.java lab9 |
before midnight today.
For the Lead TA:
|