CS 3291 (Java with Internet Applications):
Homework #1
- Assigned:
- September 10, 1999.
- Due:
- September 17, 1999, class time.
- Credit:
- 10 points.
- Objective:
- Define and use a class.
- Description:
- You are to implement a simple Clock class, with a constructor
method and methods to reset the clock, increment its value,
and display its value. The template code gives details.
- Instructions:
-
- Download template source code
(Clock.java).
- Replace comments of the form
// Your code/declarations go here.
with declarations and code to implement the
methods as described in the comments.
Also replace your name, SSN, and e-mail address
in the comments at the top of the source code,
and (optionally) fill in the "time spent" comment.
- Test the program until you are satisfied that it works.
See Java tips for
help with compiling and executing.
- Submit as described in
How to submit homework.
- Grading:
- This homework is worth 10 points:
- 8 points for correctness. I will evaluate this
in two ways:
- I will execute your program using command-line
arguments as described in the template source
code.
- I will invoke your class from our test program,
to check that your definition conforms to the
interface given in the template source code.
- 2 points for programming style.
See Programming style
for notes on what I consider good programming style.
(For this assignment, style should not be much of an
issue since you are simply filling in the blanks of
the "template" code.)
- Helpful hints:
-
- Here are some methods you may find useful. These methods
are part of the standard language package; you do not
need any import statements to use them.
- Integer.parseInt(String s) returns an
integer; e.g.
Integer.parseInt("10") returns the
integer 10.
- System.out.print(String s) and
System.out.println(String s)
print strings to standard output, without and
with (respectively) an end-of-line marker.
If you call either method with an argument
that is not a string, the argument will be
converted into a reasonable printable
representation and written to standard output.
- If s1 and s2 are strings,
s1.equals(s2)
returns a boolean indicating whether
the two strings have the same value.
(The expression s1 == s2 compares
not the values of the strings but the
values of the references, and thus yields
true only when
s1 and s2 are the
same object.)
- Recall that + denotes concatenation when
applied to strings, and note
that you can convert anything
to a string by concatenating it with another string.
For example, the value of
"ab" + 10 is a string with value
"ab10".