{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Spring08_PracticeFinalExam

# Spring08_PracticeFinalExam - CS1316 Spring 2008 Practice...

This preview shows pages 1–5. Sign up to view the full content.

CS1316 Spring 2008 Practice Exam Final NAME: ___________________________________ PRISM ID:_______________________________ 1 Part I: Random Generators and Picture Methods Using Math.random() or the Random class, construct a method to solve the following problem. Write a new method in AdvancedPicture that will randomly change the pixels of the AdvancedPicture . There is a 40% chance that the pixel will have the red value maximized. 20% chance for the green value. 15% chance for the blue value. 25% chance that all green, blue and red values are set to 0. (Hint: Max value is 255). public void randomizePixels() public void grayscale(){ Pixel[] pixels = this.getPixels(); for (int i = 0; i < pixels.length; i++){ int intensity = (int) ((pixel[i].getRed() + pixel[i].getGreen() + pixel[i].getBlue()) / 3); pixel[i].setColor(new Color(intensity,intensity,intensity)); } }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document