Q: How do I read two integers on one line in the
A: Just prompt once and then call
nextInt twice in a row.
Q: When I try to run my Date class, I get the following error. Why?
Exception in thread "main" java.lang.NoSuchMethodError: main
A: Don't run
Q: I don't understand constructors. Do I have to have a constructor? What should my constructor do?
A: Yes, you need a constructor. Its job is to initialize new objects as they are created. See Section 8.3 of the textbook to learn more about constructors and what they are supposed to do.
Q: How do we use a value that's passed in to the constructor, in another method of that class?
A: Make the object "remember" that value for use later. How do we make objects "remember" things?
Q: I tried to write a
equals method and it compiles, but when I run the program, it doesn't seem to be calling my method! Why not?
A: Check to make sure the method headers exactly match what is expected. Classes with methods such as
tostring (capitalized improperly) or
toString(int a, int b) (incorrect parameters) will compile but will be silently ignored.