Spring Semester 2005

Lecture Notes Sixteen: Visualizing Objects for Lab Eight.

Here's some code we will discuss:

```class Point {
double x, y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
public String toString() {
return "I am a Point at (" + x + ", " + y + ")";
}
}

class Circle {
Circle(double r, double x, double y) {
this.x = x;
this.y = y;
}
Point center() {
return new Point(this.x, this.y);
}
}
}

class Rectangle {
double x, y, width, height;
Rectangle(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
} ```
Then there's this set of problems. And the solutions are posted here (and briefly reviewed here).

There's also an older lab that illustrates the process in greater detail.

Now the rest of the notes (below) simply illustrates how we will use our visualization tool.

Start BlueJ.

Choose Project.

Select New Project.

Give it a name.

`Sixteen` in my case.

Click on Create.

Then Create a New Class.

Give it a name first.

`BankAccount`, in my case.

It's been created.

Double-click on it.

Template code is provided. Highlight it.

And erase it. You don't need it.

Write the code.

Press Compile (that amounts to `javac`).

The left border turns white if compilation succeeds.

Close the window: a compiled class also has a different outlook.

Right-click on it: you can create instances of it (objects).

The first one we create should be called `one`.

We can see it at the bottom.

Create another one, in a different way (run the other constructor).

This constructor wants an initial balance.

So we start by giving it a name (`two`).

Then we set the initial balance to be 50.

So now let's inspect these objects.

Right-click on the first one.

Choose Inspect.

You can see what's inside.

Do the same with the other one.

You see the contents is different.

So now let's work with the first one: choose `deposit(amount)`.

The instance method wants an argument (it has one parameter).

So you put 30 in, push OK, then inspect.

It's there. You now know BlueJ. What's left is to learn some object-oriented programming.

Last updated by Adrian German for A201/A597/I210 on `Tue Mar 1 09:58:23 EST 2005`