/**************************************************************************
* File: GeoWorldEx.java
* Title: Example GeoWorld, for ILS614, In Class exercise
* Programmer: Terry E. Weymouth
* Description: This program defines a world of geometric objects
* (rectangles) to illustrate several basic
* concepts of object classes and object instances. It is the
* bases for an in-class example. February 1, 1996.
* Running the program will create a couple of rectangles
* and print out their descriptions.
* History:
* Created and debugged 01/18/96. TEW
* Modified for in Class Use 02/01/96. TEW.
*
* Last Modified on Thursday February 1, 1996. TEW.
*
***************************************************************************/
class GeoObject {
protected int baseX;
protected int baseY;
public GeoObject (int x, int y) {
baseX = x;
baseY = y;
}
public int testMethod(int number1) {
int number2;
number2 = number1 + 30;
System.out.println("This is number 1: " + number1 +
" and this is number 2: " + number2 + ".");
return(number2);
}
public void printIt () {
System.out.println("GeoObject: base = (" +
baseX + ", " + baseY + ").");
}
}
class Rectangle extends GeoObject {
private int itsWidth;
private int itsHeight;
public Rectangle(int x, int y, int width, int height) {
super(x,y);
itsWidth = width;
itsHeight = height;
}
// What would happen if I were to insert this code
//
// public int testMethod(int somthingElse) {
// int anyNumber = 90;
// System.out.println("This is a test: " + anyNumber +
// ", " + somthingElse + ".");
public void printIt () {
System.out.println("Rectangle: base = (" +
baseX + ", " + baseY + "), height = " +
itsHeight + ", width = " + itsWidth);
}
}
public class GeoWorldEx {
public static void main (String args[]) {
System.out.println("Starting GeoWorld");
Rectangle r = new Rectangle(20,30,40,50);
r.printIt();
r.testMethod(5);
int number2 = 34;
int results = r.testMethod(number2);
// What would have happened if I had said
// number2 = r.testMethod(number2);
System.out.println("The results are: " + results + ".");
}
}