Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto, 2002.

[Contents] [Next] [Previous]

Lab 1: Introduction to Lab. Environment and Object Orientation


HexCell Class

The Hex Cell Class is a subclass of Cell Class. It is a specialized cell which only handles hexagonal shape cells. Thus, there should be some overrides in the class definition to make it more specialized.

The special classification of a Hex Cell Class is as follows:

These definitions can be implemented in Java Language as follows :

File name: HexCell.java

Class Fields :

Class Constructors:

Class Methods:

import java.lang.Math; 
// Required by Math.sqrt() static method call in the class definition
/**
 * A Circle Cell 
 * 
 * @author: CPwJ
 * @version: 1.0 (2002)
 */
public abstract class HexCell extends Cell
{
	// instance variables 
	//Information about a cell (x,y coordinate and r cell radius)
  private static final double RATIO = 2.5980762;  //ratio used in area calculation
private static final String CELLTYPE = "Hexagonal"; //type of cell shape
/**
* CircleCell constructor
* @param x Cell X coordinate
* @param y Cell Y coordinate
* @param r Cell Radius
*/

public HexCell(double x, double y, double r)
{
super(x,y,r);
}
/**
* Calculate the area of a Circle shape Cell
* @return the area of the Circle Cell
*/

public double area()
{
return RATIO*getR()*getR();
} /**
* Check whether a point is covered by the Hex cell
* @param x The x point of access coordinate
* @param y The y point of access coordinate
* @return True/False
*/

public boolean coverage(double x, double y)
{
double relativeX = Math.abs(x-getX());
double relativeY = Math.abs(y-getY());
if ( relativeY > yLimit(relativeX) ) return false;
return true;
}
/**
* Calculate the first quardrant of Hex boundary
* @param x The x point of access coordinate
* @return The Y boundary
*/

private double yLimit(double x)
{
double r = getR();
double maxY = r * Math.sin(Math.PI / 3);
double minY = 0.0;
if ( x < r/2 ) return maxY;
if ( x > r ) return minY;
return (2 * maxY * (1 - x / r) );
}
}
 

[Contents] [Next] [Previous]