CS 140 - Test 2 Study Guide

Make sure review the four homework assignments, all of the labs we've done, and the examples we've written in class. Alos, I may ask some questions from Exam 1.

  1. Write a Java program that asks the user to enter an amount of money in dollars they wish to gamble and a number between 1 and 6 (inclusive) and then simulates rolling a six-sided die. If the die mathces the number the gambler entered they win one dollar otherwise they lose one dollar. The simulation should continue until the gambler has either doubled their money or lost everything. The program should graph the gamblers winnings as a line graph (much like we did for tossing a coin).
  2. Write a Java Picture method named makeBlurry that animates filling in a picture with random colors at random locations within the picture. Have the user pass in as a parameter how many random pixel changes they want to make. Repainting after every pixel change is slow, so have your method repaint every tenth pixel to speed things up (don't use Util.sleep, that will really slow it down). For example the call, in my solution, the code below results int the blurry bug by randomly modifying pixels 150,000 times.
      String path = "T:/Harcourt/Fall2008/CS140/gallery/";
      Picture pic1 = new Picture(path + "bug.jpg");
      pic1.makeBlurry(150000);
    
  3. Write a method flipHorizontal that flips a picture horizontally. For example, here is the bug flipped horizontally. (Contrast this with the original.)
  4. Write a method rotateLeft that rotates a picture ninety degrees counter clockwise. For example, here is the bug rotated left. (Contrast this with the original)
  5. Write a method morph that changes a picture into another picture from the top down. For example, assuming pic1 and pic2 are the same exact dimensions
    pic1.morph(pic2);
    
    will change pic1 into pic2 row by row starting at the top.
  6. Make sure all of your methods from class and the labs are in your Picture.java file and work properly so you can use them.

Here's my sample main program for the study guide methods (except for the first program that simulates rolling a die.

        public class Exam2StudyGuide {
        
          public static void main(String [] args) throws Exception {     
            String path = "T:/Harcourt/Fall2008/CS140/gallery/"; 
            Picture pic = new Picture(path + "bug.jpg");
            Picture pic1 = new Picture(path + "colors_small.jpg");
            Picture pic2 = new Picture(path + "mutant_lemon_small.jpg");
        
            pic.flipHorizontal().repaint();
            pic.makeBlurry(100000);
            pic.flipHorizontal().repaint();
            pic.rotateLeft().repaint();
            pic1.morph(pic2);    
          }
        }