java中程序名称可以用拼音嘛,4、编写一个Java应用程序,包括类Rectangle、Volume和主类(名称为自己姓名的拼音),各个类具体要求如下...

共回答了18个问题采纳率:94.4%

public class Rectangle {

private double width = 1;

private double length = 1;

public Rectangle() {

}

Rectangle(double width, double length) {

this.length = length;

this.width = width;

}

public double getWidth() {

return width;

}

public double getLength() {

return length;

}

public void setWidth(double w) {

width = w;

}

public void setLength(double l) {

length = l;

}

public double area() {

return width * length;

}

}

///

public class Volume extends Rectangle {

private double height = 1;

public Volume() {

}

public Volume(double width, double length, double height) {

super(width, length);

this.height = height;

}

public void setHeight(double h) {

height = h;

}

public double getHeight() {

return height;

}

public double volume() {

return getWidth() * getLength() * height;

}

public double area() {

return getWidth() * getLength() + getWidth() * height + getLength()* height;

}

}

//

public class sunzhiyang{

public static void main(String[] args) {

Volume v = new Volume(3.0, 4.0, 5.0);

System.out.println( v.area());

System.out.println( v.volume());

}

}

1年前

6