/* Project 8 Course:CIS260 Title: Oval Class Written by: William K Irvine Date Completed: 7/12/2000 */ import java.awt.*; public class Oval extends TwoDimensionalShape // inherits from the super class { private double width, height; public Oval() // No-argument constructor { setWidth( 1.0 ); // implicit call to superclass constructor setHeight( 1.0 ); } public Oval( int x, int y, double w, double h) // constructor method { super( x, y ); // explicit call to super class constructor setWidth ( w ); setHeight( h ); } // Set height and width public void setWidth ( double w) { width = ( w > 0 ? w : 1.0 ) ; } public void setHeight( double h ) { height = ( h > 0 ? h : 1.0 ) ; } // Get height and width public double getWidth() { return width; } public double getHeight() { return height; } // Calculate area of a Oval public double area() { return Math.PI * width / 2 * height / 2; } //method draw public void draw( Graphics g ) { g.drawOval( Math.abs( super.getXCoord() ), Math.abs( super.getYCoord() ), Math.abs( (int)this.getWidth() ), Math.abs( (int)this.getHeight() ) ); } //get name of Oval public String getName() { return "Oval: ";} // Convert the Oval to a String public String toString() { return super.toString() + "; Width = " + width + "; Height = " + height + ";"; } }
Preface | Castle Irvine | Drum Castle | Irvine Clan | A Beginning A Brief History | Surnames | Poetry & Pros | Pictures | I.Q.Test | Privacy
© 1998 - 2006 www.Irvineclan.com. All rights reserved. Having a Problem with the site? Send Email.