Chapter 1

Exercise 1.9

The main building:
  • Create a new Square object
  • Invoke its method makeVisible()
  • Make the square bigger by invoking the method changeSize(newSize) (100 is a good size)
  • Move the square down by invoking the method moveVertical(distance) (again 80 is a good value)
The window:
  • Create a new Square object.
  • Invoke its method makeVisible()
  • Change its color by invoking changeColor()
  • write "black" in the popupwindow
  • Move the square down by invoking the method moveVertical(distance) (100 is a good value)
  • Move it to the right by invoking moveRight()
The roof:
  • Create a new triangle object.
  • Invoke its method makeVisible()
  • Change its size with changeSize(newHeight, newWidth) (50,140)
  • moveVertical(70)
  • moveHoizontal(60)
The Sun:
  • Create new Circle object.
  • Invoke its method makeVisible()
  • Change its color by invoking changeColor() (write "yellow" in the popupwindow) Optionally change its size with changeSize(60)
  • Move it to the right by invoking moveHorizontal(180)
Exercise 1.11
  • It uses the objects of the classes Circle, Square and Triangle.
  • It then moves these objects to the right places and changes the sizes and colors of the obejcts. Essentially calling the same methods as used in exercise 1.9
Exercise 1.15

After the line sun.makeVisible() insert the following:
  • sun.slowMoveVertical(250);
  • Compile the Picture class (Press compile in the editor window)
  • Create instance of class Picture and invoke its draw() method.
Exercise 1.16

Remove the line (if added in the previous exercise): slowMoveVertical(250); Right below the last } after the draw() method, add the sunset() method :
/**
 * Animates the sunset.
 */ 
public void sunset() {
    sun.slowMoveVertical(250);
}
Compile! And run it.
Exercise 1.18

When calling the method getName(), the name of the student is displayed in a popup window. The name displayed is the one typed in when the object was created.
Exercise 1.20

It shows the number of students in the labclass which is zero.

Exercise 1.27

0 int
"hello" String
101 int
-1 int
true boolean
"33" String
3.1415 double

Exercise 1.28

First you would have to decide which type the field should have. String would be a good type to hold a name, so we add the following line to the source file of Circle:

    private String name;

The above line could be placed after this line in Circle.java:

    private boolean isVisible; 

Exercise 1.29

public void send(String msg)

Exercise 1.30

public int average(int firstNumber, int secondNumber)

Exercise 1.31

The book is an object. The class could be book.

Exercise 1.32

Yes, an object can belong to several classes. One of the more famous examples are the platypus, which is both a mammal and egg-laying.