current position:Home>Is a graphic inheritance problem

Is a graphic inheritance problem

2022-02-02 19:47:09 CSDN Q & A

1) Writing graphics classes Geom, Have private properties : Color and whether to fill , Define common construction methods 、 Get each
The method of multiple attributes and the method of obtaining graphic information :
(2) Write a rectangular class that inherits the graphic class Rectangle, Have private properties : Length and width , Define common construction methods 、
The method of obtaining each attribute and the method of calculating the area :
(3) Write a box class that inherits the rectangle class Rectlinder, There are private properties : high , Define common construction methods 、 a
The method of taking attributes and the method of finding volume , Method of rewriting graphic information .
(4 Design an entry main class , Construct several cubes , List their data and behavior
Define the class according to the class diagram , And then create the object , Call the member method of the class . The design of specific classes is as follows :




Refer to the answer 1:

This is not translating words into code ? Come on as required That's it




Refer to the answer 2:



Refer to the answer 3:
/** * 1)  Writing graphics classes  Geom, Have private properties : Color and whether to fill , Define common construction methods 、 Get each  *  The method of multiple attributes and the method of obtaining graphic information : */public class Geom {    private String color;    private String filling;    public Geom(String color, String filling) {        this.color = color;        this.filling = filling;    }    public String getColor() {        return color;    }    public void setColor(String color) {        this.color = color;    }    public String getFilling() {        return filling;    }    public void setFilling(String filling) {        this.filling = filling;    }    @Override    public String toString() {        return "Geom{" +                "color='" + color + '\'' +                ", filling='" + filling + '\'' +                '}';    }}



Refer to the answer 4:



Refer to the answer 5:
package entity;/** * (3) Write a box class that inherits the rectangle class Rectlinder, There are private properties : high , Define common construction methods 、 a  *  The method of taking attributes and the method of finding volume , Method of rewriting graphic information . */public class Rectlinder extends Rectangle{    private Double height;    public Rectlinder(Double length, Double width, Double height) {        super(length, width);        this.height = height;    }    public Double getHeight() {        return height;    }    public void setHeight(Double height) {        this.height = height;    }    public Double getVolume(Double length, Double width, Double height){        return  length * width * height;    }    @Override public String toString() {        return "Rectlinder{" +                "length=" + super.getLength() +                "width=" + super.getWidth() +                "height=" + height +                '}';    }}



Refer to the answer 6:



Refer to the answer 7:
package entity;/** * (2) Write a rectangular class that inherits the graphic class  Rectangle, Have private properties : Length and width , Define common construction methods 、 *  The method of obtaining each attribute and the method of calculating the area : */public class Rectangle {    private Double length;    private Double width;    public Rectangle(Double length, Double width) {        this.length = length;        this.width = width;    }    public Double getLength() {        return length;    }    public void setLength(Double length) {        this.length = length;    }    public Double getWidth() {        return width;    }    public void setWidth(Double width) {        this.width = width;    }    public Double getArea(Double length, Double width){        return length * width;    }}



Refer to the answer 8:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021947069883.html

Random recommended