Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- public class Box extends Rectangle {
- private int length;
- public Box() {
- super(3, 5, 4, Color.BLUE);
- this.length = 4;
- }
- public Box(int width, int height, int length, Color color) {
- super(width, height, length, color);
- this.length = length;
- }
- public Box(int newX, int newY, int newWidth, int newHeight, int newLength) {
- super(newX, newY, newWidth, newHeight);
- length = newLength;
- }
- public void setLength (int length){
- this.length = length;
- setY((int) Math.ceil((double) length / 2));
- }
- public int getLength (){
- return length;
- }
- public int calcArea(){
- return getWidth() * getHeight() * 2 + getWidth() * length * 2 + getHeight() * length * 2;
- }
- public DrawFigure drawFigure() {
- DrawFigure box1 = new DrawFigure(2, getWidth(), getHeight(), length);
- return box1;
- }
- public int calcVolume(){
- return getWidth() * getHeight()* length;
- }
- public String toString(){
- return "Length = " + length + " " + super.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement