/** * CS139 - Programming Fundamentals * Department of Computer Science * James Madison University * @version Spring 2016 */
For this lab you will create a class
named CSColor
. Java already comes with its own Color
class (check out
the documentation
and source code), but we are going to create
a simple variant of that class. This lab was originally designed by
Prof. Arch Harris with modifications by Chris Mayfield.
Implement methods that accept objects as parameters.
Implement methods that return an object of the class.
Download a copy of Main.java. This file
provides the main method you will use to test your
implementation of CSColor
.
Download a copy
of CSColor.java. Read
the documentation for
the CSColor
class that this file implements.
Normally, to run a Java program that has the main method in a file named Main.java, you would run the following command.
java Main
But instead of sending the program output to the screen, we want the output to go to a file. So run today's lab with the following command.
java Main > output.html
This will create a file named output.html which you should view in a web browser.
Look at the parts of CSColor
that have already been completed.
A number of constants have been defined. Those constants are public so they may be used outside of the class (you should note that those constants are referenced in Main.java).
Three instance variables are
defined. Every CSColor
object that is created will
have its own copy of those three instance variables. Those
instance variables are private so they can only be accessed by
methods in the class.
The methods toString
, add
,
and dim
have already been finished. Look at those
methods and ask questions about anything that you do not
understand.
Implement the constructor. Recall that a constructor's job is to initialize an object to a particular state. Compile your Java files and run the main program as specified below. The top portion of the html file that outputs the constants should work properly after you complete the constructor.
Implement the other methods, one at a time. Rerun the program after implementing each method to test the implemented method. Make sure a method is working correctly before moving on to the next method.
When you have everything working, open two browser windows: one with your web page and one with the sample output page. Ask a TA or instructor to verify that your program produces the correct output.
Submit your CSColor.java file via Web-CAT.