Advertisement
Guest User

Cylinder.java

a guest
Feb 26th, 2022
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. // Jacobb Coates
  2. // Lab 4
  3. // February 11th, 2022
  4.  
  5. import java.awt.Color;
  6.  
  7. public class Cylinder extends Circle {
  8.     private int length;
  9.  
  10.     public Cylinder(int radius, int length, Color color) {
  11.         super(radius, length, color);
  12.         this.length = length;
  13.         this.radius = radius;
  14.     }
  15.    
  16.     public Cylinder(int newX, int newY, int newRadius, int newLength) {
  17.         super(newX, newY, newRadius);
  18.         length = newLength;
  19.     }
  20.  
  21.     public int getLength() {
  22.         return length;
  23.     }
  24.  
  25.     public void setLength(int length) {
  26.         this.length = length;
  27.     }
  28.  
  29.     public int calcArea() {
  30.         return (int) Math.ceil( 2 * 3.14 * radius * radius + 2 * 3.14 * radius * length);
  31.     }
  32.  
  33.     public int calcVolume() {
  34.         return (int) Math.ceil(3.14 * radius * radius * length);
  35.     }
  36.    
  37.     public DrawFigure drawFigure() {
  38.         DrawFigure cylinder1 = new DrawFigure(4, getRadius(), length);
  39.         return cylinder1;
  40.     }
  41.  
  42.     public String toString() {
  43.         return "Length = " + length + " " + super.toString();
  44.     }
  45.    
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement