Quick Index
Prerequisites
Add Instance Variables To Ball Class
Add Instance Variables To Rectangle Class
Prerequisites
This is a continuation of the
challenge in the previous chapter
.
In that challenge we coded up these two classes:
Ball.java
Rectangle.java
We coded up empty class bodies. This will be our starting point for this challenge.
Before getting started, add a new
working directory
for this challenge.
As always, the challenge follows the
full example
closely.
Add Instance Variables To Ball Class
Problem Statement:
Review our previous design of the Ball class
here...
We want to add an ivar for each property listed in the design
Give the instance variable "r" a data type of "int". Give all other ivars a data type of "String".
Doodle
a quick design of the work that needs to be done (optional but just for good practice - any form/style you like)
Copy "Ball.java" from the challenge in the previous chapter (an initial class with empty body) into your working directory.
Code the ivar(s) that were identified in the previous steps
Compile
Fix any compile errors
Hints:
Follow the same steps as in this chapter's "Full Example"
You should end up with two ivars for this class
The class may be simple -- i.e. just the instance variable(s) in the code body similar to the "Full Example"
You do
not
need to run the class (but you do need to compile it)
Add Instance Variables To Rectangle Class
Problem Statement:
Review our previous design of the Rectangle class
here...
We want to add an ivar for each property listed in the design
Give both instance variables a data type of "int"
Doodle
a quick design of the work that needs to be done (optional but just for good practice - any form/style you like)
Copy "Rectangle.java" from the challenge in the previous chapter (an initial class with empty body) into your working directory.
Code the ivar(s) that were identified in the previous steps
Compile
Fix any compile errors
Hints:
Follow the same steps as in this chapter's "Full Example"
You should end up with two ivars for this class
The class may be simple -- i.e. just the instance variable(s) in the code body similar to the "Full Example"
You do
not
need to run the class (but you do need to compile it)
Introduction To Objects With Java (Chapter 303 - Object Data)
Chapter 303 - Object Data
Challenge
Chapter Contents
Overview
Definition
Naming
Problem
Planning
Coding
Examples
Refs
Chapter
Top
Search
TOC