CS 140 - Homework 3 - Due Jan 30

Name:______________________________________


Read sections 3.6, 4.1, and 4.2 in your book.

Answer the following questions:

  1. To create a new Picture object you need to pass a String whose value is the path and name of a picture file on your filesystem. How do you create a new Picture object by letting the user select the picture location from a file chooser? (Section 3.6) Write the Java statement below.
  2. Once you have created a new picture object, how do you display it to the screen?
  3. Recall that not only values and variables in Java have types, but also the results of operations. What are the values and types of the results of the following operations:
  4. What kind of value is created with the following Java declaration:
      int[] values = {5, 10, 2, -6, 1};
  5. Write a line of code to print out the value of the fourth element in the above data structure. (Don't just print -6 directly, figure out how to access the value in the values object).
  6. How is the color of an RGB pixel represented?
  7. Say you already have a Picture object declared, like the following:
            Picture p = new Picture(FileChooser.pickAFile());
    	 

    Write a Java statement (or several statements) to get the pixel at location (55,121) from picture p and set its green value to 128.

  8. What line of code must you execute in order to avoid the error message Error: Undefined class Color when trying to create a new Color object?
  9. Write a Java statement to create a new Color object whose color is completely blue:

© Rich Sharp (modified by Ed Harcourt)