Example 23.18: The Cone subclass

By now you should be getting a feel for how these things work. Example 23.18 is a Cone class that has bottomRadius and height fields.

package elharo.vrml;

public class Cone extends shape {

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

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

  }

  public String draw() {
  
    String node1 = "Translation { \n" +
      "translation " + x + " " + y + " " + z + 
      "\n}\n\n";
      
    String node2 = "Cylinder {\n" + 
      "  bottomRadius " + bottomRadius +
      "\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