Java Reference
In-Depth Information
3. Add a constructor to Television that takes in two ints, one for channel
and one for volume. Be sure to invoke the mutator methods instead
of having the constructor assign the parameters to the fields.
4. Save and compile the Television class.
5. Write a class named WatchTelevision that contains main(). The first
command-line argument will be the volume, and the second one
will be the channel. Use the Integer.parseInt() method to parse these
values into ints.
6. Instantiate a Television using the two command-line arguments;
then print out the channel and volume using the accessor methods
of Television.
7. Try to change the volume or channel to an invalid value.
8. Save, compile, and run the WatchTelevision class.
Run the program several times with different values for the volume
and channel. You should not be able to set the volume outside of the
range 0 to 10 nor set the channel outside the range 2 to 999.
Lab 7.3: Using static Methods
The purpose of this lab is to become familiar with writing and using sta-
tic methods.
1. Begin by declaring a class named FormatTest. This class is going to
be used to verify that data fits a certain format.
2. Add a static field of type int named maxStringLength. Also add a
static field of type double named minSize.
3. Add a static method named testStringLength() that has a String
parameter and returns a boolean. This method should return true
if the string passed in is less than or equal to the maxStringLength
field; otherwise, the method should return false.
4. Add a static method named testDouble() that has a double param-
eter and returns a boolean. It should return true if the double
parameter is greater than or equal to the minSize field; otherwise,
it should return false.
5. Save and compile the FormatTest class.
Search WWH ::




Custom Search