Advertisement
Guest User

Box.java

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