Lets take a step back and review what we have covered so far in this course. Its possible that you will not finish this lab today. If you don't finish it today, finish it for Monday and get checked off on Monday.
Lab7 that writes
"Hello World" to the console. Try and do this from memory.
If you get stuck go ahead a look in the book.
println statement that says
// Part I
This marks the part of your main method that pertains to part I.
println statement and proceed to the next section.
We do this so
we don't see the "Hello World" message every time we run the program
in the remainder of the lab. But it still leaves the code in there so you can refer
back to it.
// Part II
main method to declare a variable average that will hold the average of a list of integers. Initialize average to 0.0.
x, y, z to hold the values 97, 63, and 34.
x, y, z into
average.
println statement to print the message The average is ______ .
The correct average should show up where the ______ is. Make
sure the decimal part is correct.
Edit -> Comment Lines from the menu.
// Part III
for (int i = 0; i < 10; ++i) {
System.out.print(i + " ");
}
sum immediately before the for-loop.
Make sure to initialize
sum to 0. Now you need to
keep adding i to sum inside the for loop (the stuff
between the for-loop braces).
Do this using the following line inside the for-loop.
sum = sum + i;
The way to think about the statement
sum = sum + i; is
Take the old value of sum, add i
to it, then stick the result back in the variable sum.
sum to the console. Print a nice message
such as
The answer is ___________
// Part IV
World object and put a Turtle on it. If you get stuck and can't remember go ahead and look, but at this point in the semester you should be able to recite from memory how to do this.
main method use a for-loop to make your turtle go in a circle. Copy the
for-loop from part III above and change the loop body to use a
forward and turn method call.
World and Turtle objects.
Proceed to the next section.
Turtle.java file add a method named circle that
makes a turtle go in a circle.
circle method on a turtle object.
Turtle class as
opposed to putting the for-loop directly in the main method? Write your answer below.
main method that allows the user to choose a picture
to display using a dialog box and then displays the selected picture.
You'll need to declare a String object (to hold the file name) and a
Picture
object and then call the ___________ method to show it.
"T:/Harcourt/Spring2008/CS140/gallery/yummy.jpg"
grayScale method you built in the previous lab. It should still
be in your Picture class.
Picture class that modify images;
methods such as grayScale and extractRedChannel.
Review the grayScale method below.
public void grayScale() {
Pixel [] pixelArray = this.getPixels();
for (Pixel pixelObj : pixelArray) {
int r = pixelObj.getRed();
int g = pixelObj.getGreen();
int b = pixelObj.getBlue();
int val = (r + g + b) / 3;
pixelObj.setColor(new Color(val,val,val));
}
}
grayScale
method above that briefly
explains what that line does. Don't forget the first line that starts with the
Java keyword public and the very last line that contains
just the }
// Part V to your main method in Lab7.
"T:/Harcourt/Spring2008/CS140/gallery/sunset.jpg"
decreaseRed to
your Picture class that decreases the amount of red in a picture by 20%.
decreaseRed method on the sunset picture and display the new picture.
Modify the method decreaseRed so that it takes a
parameter which represents the scaling factor, the amount we
need to decrease the red by. Use this parameter value instead
of hard coding the value to decrease it by 20%. Modify the main
program to pass in a scaling value when you call the decreaseRed method.