CS 10, Fall 2008
Assignment 1
Due: Wednesday, October 8, 9:00pm
Worth: 100 homework points
- Do Exercises P2.5 and P2.6 on page 76 of the text, with the following modifications:
- Write one Java application named
ColorDemo.java
(not the separate BrighterDemo and DarkerDemo programs suggested in the text).
- Add comment lines at the beginning of the file that include your
name and the date the program is written.
(This is IMPORTANT, and it applies to all future programs too.)
- Learn what's necessary about Java colors in section 2.13.1 (pp. 67-68) and
Project 2.2 (p. 78), as well as the text of Exercises P2.5 and P2.6.
Be sure to
import java.awt.Color
.
- Instead of printing the colors as suggested in the text, use
class CS10Display
to show them graphically. First download a copy of
CS10Display.class (another copy is
in ~mikec/cs10/hw1/
at CSIL). This class was created for use in CS 10
assignments this quarter - here is its public interface
(but all you need for this assignment is the show
method).
Store the class file in the same directory as your ColorDemo.java, and use the show
method to show your colors. For example, the following two statements would show the color red
in one display, then show the colors red, white and blue in a second display:
CS10Display.show(Color.RED);
CS10Display.show(Color.RED, Color.WHITE, Color.BLUE);
- Your program should present two displays too:
- The color specified in Exercise P2.5, and the color that results after using the
brighter
method as directed - both in the same display.
- Similar to (but not exactly) the directions in Exercise P2.6, show
Color.RED
and the effects of using the darker
method once, twice and three times on
that starting color - four colors altogether in the same display.
Your results should exactly match these
part 1 results from our solution.
- Write FiveColorScale.java
as a class that represents a five-color scale, and with a public interface that matches
our solution's FiveColorScale interface.
- The idea is that a FiveColorScale object is created by specifying a first color (level 1),
and a last color (level 5). The object then calculates the three intermediate colors (levels
2, 3 and 4) so that the five colors in order look like a smooth transition from the first
through the last colors.
Hint: use the getRed
, getGreen
and getBlue
methods of the Color class and calculate average colors using these values.
- Be sure to
import java.awt.Color
again, and include all the necessary public features.
- Both a no-argument constructor that sets the first color to
Color.WHITE
and the last color
to Color.BLACK
:
public FiveColorScale()
and a 2-argument constructor that lets a client set first and last colors:
public FiveColorScale(Color first, Color last)
- The five methods,
get1()
, get2()
, and so on that provide access to each
of the five colors.
- For this class, you also must provide proper javadoc comments for every public declaration
- class, constructors and methods. Include
@param
and @return
tags
as appropriate. Use the javadoc utility to verify your comments do not generate warning messages:
javadoc FiveColorScale.java -d docs
And be sure to examine the resulting docs/FiveColorScale.html
to know if they are complete.
- Use a copy of this application, FiveScaleTester.java
(another copy is in
~mikec/cs10/hw1/
at CSIL) to test
the class. Read the application to know how it is using your class, and insure that results match these
part 2 results from our solution.
- Test the classes you wrote for parts 1 and 2 at CSIL.
- If you do not already have a College of Engineering user account, then sign up
here
now. Hopefully you are signing up well before the deadline, as your account will not be
ready to use immediately. When it is ready, verify you can access it, and change your password
as instructed!
- Download and install PuTTY, or SecureCRT (see the Resources page for links) or another secure
shell program on your own computer if you have one. Then verify that you can log in to your account
remotely. You may also use the CSIL
lab (Harold Frank Hall 1138) itself.
- Create copies of the java classes from parts 1 (ColorDemo.java) and 2
(FiveColorScale.java and our FiveScaleTester.java), as well as CS10Display.class in your CSIL account.
Then compile and execute them using the JDK tools at CSIL. Notice that CS10Display will
just print the colors if you are not working in a shell with graphical abilities - don't worry about that
(here are non-graphical runs we did at CSIL by remote access).
- Fix any errors before proceeding to the turn-in step.
- Complete this Student Information Form.
Then turn in the two required files at once
from your engineering account as follows:
turnin hw1@cs10 ColorDemo.java FiveColorScale.java
Late projects may not be accepted.
Updated 9/24/08 by C. Michael Costanzo