Next: Lab Exercise 2: Modifying
Up: In the Laboratory: Feeding
Previous: Problem Statement
Download the CyberPet.java and the TestCyberPet.java
source files. Compile and run the program, which corresponds to the programs
developed in this chapter.
For each of the items below, make the editing change and then recompile
the program. Make note of any error messages that are generated by the compiler.
Try to understand what the message is telling you, and try to learn from the
error, so it will be less likely to occur next time. After you have finished
with that error, restore the code to its original form and move on to the
next item.
- Java is case sensitive. Change the assignment statement in
setName() to Name = str with an uppercase ``N.''
- Strings require double quotes. Leave off one of the double
quote marks around ``Socrates'' in the main() method in TestCyberPet.
- Methods that return a value require a return statement.
Comment out the return statement in the getName() method.
That is, turn the return statement into a comment line by adding
double slashes (//) at the beginning of the line.
- String concatenation requires an operator. Delete the plus
sign (+) in the System.out.println() expressions in main().
- Objects must be instantiated. Comment out the line beginning
pet1 = new Pet("Socrates") in main().
Next: Lab Exercise 2: Modifying
Up: In the Laboratory: Feeding
Previous: Problem Statement
Ralph Morelli {Faculty}
12/22/1999