a704522512 2020-03-27 15:14 采纳率: 0%
浏览 183

大佬们这题我这么写可以吗

图片说明

package Rectangle;
public class Rectangle{
private double length;
private double width;
private static int id;
private double mianji;
private double zhouchang;
public Rectangle(){
}
public Rectangle(double length,double width){
this.length =length;
this.width = width;
}
public double computemianji(double length,double width) {
mianji=length*width;
return mianji;
}
public double computezhouchang(double length,double width) {
zhouchang=(length+width)*2;
return zhouchang;}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public String toString() {
return "长度为"+length+"宽度为"+width;
}
static int id() {
return id;
}

static {

id=1;

}

}

下面是main

package Rectangle;
public class 矩形 {
public static void main(String[] args) {
Rectangle one = new Rectangle(2.5,4);
System.out.println("当长为4,宽为2.5时矩形的面积为"+one.computemianji(2.5,4));
Rectangle two = new Rectangle(10,30);
System.out.println("当长为30,宽为10时矩形的周长为"+two.computezhouchang(10,30));
Rectangle three = new Rectangle(4,10);
three.setWidth(4);
three.setLength(10);
System.out.println("矩形的长为"+three.getWidth()+"矩形的宽为"+three.getLength());
Rectangle five = new Rectangle(4,10);
System.out.println(five.toString());
Rectangle six = new Rectangle(4,10);
System.out.println(six.id());
Rectangle seven = new Rectangle();
System.out.println(seven);
}
}

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)