Shape.java
package com.bozoid.cis370.hw02;
import java.text.*; // for NumberFormat
/**
A base class for shapes (Rectangle, Circle, etc.).
@author Walt Leipold
*/
public abstract class Shape
{
/**
Construct an abstract <code>Shape</code>.
@param x x-coordinate of <code>Shape</code> location
@param y y-coordinate of <code>Shape</code> location
*/
public Shape(double x,double y)
{
this.x = x;
this.y = y;
}
/**
Move this <code>Shape</code> to a new location.
@param new_x x-coordinate of new location
@param new_y y-coordinate of new location
*/
public void translate(double new_x,double new_y)
{
x = new_x;
y = new_y;
}
/**
@return the x-coordinate of this <code>Shape</code>
*/
public double getX()
{
return x;
}
/**
@return the y-coordinate of this <code>Shape</code>
*/
public double getY()
{
return y;
}
/**
@return a <code>String</code> describing this shape
*/
public abstract String toString();
/**
Format a double-precision number for <code>toString()</code>
methods in subclasses.
@param x the number to format
@return the number formatted as a <code>String</code>
*/
public String formatNum(double x)
{
return nf.format(x);
}
private static NumberFormat nf = null;
static {
nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(5);
}
private double x,y;
}