Held: Thursday, April 2, 1998
Today each person will present the work they've done (hopefully).
public)
class and
the name of the class. Custom says that we capitalize the names
of classes.
class
with public.
public we use with the class).
boolean, for true/false values
char, for characters (unlike many other languages,
Java officially supports more than just the basic American
set; it has built-in support for full Unicode)
byte, for very small integers in the range -128 to
127 (integers are numbers without fractional portions)
short, for small integers in the range -32,768 to 32,767.
int, for integers in the approximate range -2 billion to
2 billion
long, for integers in a much bigger range
float, for numbers that may have a fractional
component (e.g., 10.32533).
double, for better accuracy
public class Point
{
protected double xpos;
protected double ypos;
}
Point has two attributes, each of
type double. (That is, each attribute is a number.)
/**
* A simple representation of Points.
*
* @author Samuel A. Rebelsky
* @version 1.2 of April 1998
*/
public class Point
{
/**
* The x position of the point.
*/
protected double xpos;
/**
* The y position of the point.
*/
protected double ypos;
} // Point
class-name variable-name = new class-name()
Point pt = new Point()
return statement).
/**
* A simple representation of points.
*
* @author Samuel A. Rebelsky
* @version 1.2 of April 1998
*/
public class Point
{
// +------------+----------------------------------------------
// | Attributes |
// +------------+
/**
* The x position of the point.
*/
protected double xpos;
/**
* The y position of the point.
*/
protected double ypos;
// +-----------+-----------------------------------------------
// | Modifiers |
// +-----------+
/**
* Set the location (value) of our point.
*/
public void setLocation(double x, double y)
{
xpos = x;
ypos = y;
} // setLocation(double, double)
// +-----------+-----------------------------------------------
// | Accessors |
// +-----------+
/**
* Get the x component of this point.
*/
public double getX()
{
return real_part;
} // getReal
/**
* Get the y component of this point.
*/
public double getY()
{
return imaginary_part;
} // getImaginary
} // Point
Point class, we'll have two constructors:
/**
* Initialize to (0,0);
*/
public Point()
{
xpos = 0.0;
ypos = 0.0;
} // Point()
/**
* Initialize to (x,y)
*/
public Point(double x,double y)
{
xpos = x;
ypos = y;
} // Point(double,double)
DrawableObject class
and refine that to particular drawable objects, such as Circle
or Square.
extends keyword.
public class Circle
extends DrawableObject
{
...
} // Circle
DrawableObject obj = new Circle();
public void drawWithStrangeColors(DrawableObject obj)
{
...
} // drawWithStrangeColors(DrawableObject)
...
drawWithStrangeColors(new Circle());
extends clause,
Java assumes that your object extends java.lang.Object.
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Thu May 7 10:53:54 1998.
This page generated on Thu May 7 10:58:51 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu