Example 23.17: The Cylinder subclass

Example 23.17, the Cylinder class is similar to the Cube class except that it has radius and height fields instead of height, width and depth fields.

package elharo.vrml;

public class Cylinder extends shape {

  double radius = 1.0;
  double height = 1.0;
  
  public Cylinder() {
  }
  
  public Cylinder(
   double radius, double height) {
 
    this.radius = radius;
    this.height = height;
  }
    
  public Cylinder(
   double radius, double height,
   double x, double y, double z) {
 
    this.radius = radius;
    this.height = height;
    this.x = x;
    this.y = y;
    this.z = z; 
  }

  public void sizeTo(double radius, 
    double height) {
 
    this.radius = radius;
    this.height = height;
    
  }
  
  public void sizeRelative(double radius, 
    double height) {
 
    this.radius += radius;
    this.height += height;

  }

  public String draw() {
  
    String node1 = "Translation { \n" +
      "translation " + x + " " + y + " " + z + 
      "\n}\n\n";
      
    String node2 = "Cylinder {\n" + 
      "  radius " + radius +
      "\n  height " + height + 
      "\n}\n\n";
  
    String node3 = "Translation { \n" +
      "  translation " + -x + " " + -y + " " + -z + 
      "\n" + "}\n\n"; 

  
    return node1 + node2 + node3;
    
  }

}

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home