Java Reference
In-Depth Information
You can find more details of conditional statements and the form their tests can take in
Appendix D.
Self-review exercises
This chapter has covered a lot of new ground, and we have introduced a lot of new concepts.
We will be building on these in future chapters, so it is important that you are comfortable
with them. Try the following pencil-and-paper exercises as a way of checking that you are
becoming used to the terminology that we have introduced in this chapter. Don't be put off
by the fact that we suggest that you do these on paper rather than within BlueJ. It will be
good practice to try things out without a compiler.
Exercise 2.64 List the name and return type of this method:
public String getCode()
return code;
Exercise 2.65 List the name of this method and the name and type of its parameter:
public void setCredits(int creditValue)
credits = creditValue;
Exercise 2.66 Write out the outer wrapping of a class called Person . Remember to in-
clude the curly brackets that mark the start and end of the class body, but otherwise leave the
body empty.
Exercise 2.67 Write out definitions for the following fields:
a field called name of type String
a field of type int called age
a field of type String called code
a field called credits of type int
Exercise 2.68 Write out a constructor for a class called Module . The constructor should
take a single parameter of type String called moduleCode . The body of the constructor
should assign the value of its parameter to a field called code . You don't have to include the
definition for code , just the text of the constructor.
Exercise 2.69 Write out a constructor for a class called Person . The constructor should
take two parameters. The first is of type String and is called myName . The second is of type
int and is called myAge . The first parameter should be used to set the value of a field called
name , and the second should set a field called age . You don't have to include the definitions
for the fields, just the text of the constructor.
Search WWH ::

Custom Search