中易网

用java设计一个长方形类,成员变量包括长和宽.方法:计算面积和周长,有相应的set和get方法

答案:2  悬赏:80  
解决时间 2021-03-21 14:49
用java设计一个长方形类,成员变量包括长和宽.方法:计算面积和周长,有相应的set和get方法
最佳答案

class Rectangle{

private double width;

private double height;


public Rectangle(double width, double height){
this.width = width;
this.height = height;
}


public double getArea(){
return this.width * this.height;
}


public double getGirth(){
return 2 * (this.width + this.height);
}

public double getWidth(){
return this.width;
}

public void setWidth(double width){
this.width = width;
}

public double getHeight(){
return this.height;
}

public void setHeight(double height){
this.height = height;
}
}

public class Test {
public static void main(String[] args){
Rectangle rect = new Rectangle(2,3);
System.out.println("长方形的宽 :" + rect.getWidth());
System.out.println("长方形的高 :" + rect.getHeight());
System.out.println("长方形的面积:" + rect.getArea());
System.out.println("长方形的周长:" + rect.getGirth());
}
}
全部回答
public class Rectangle
{
private double length;
private double width;
public void setEdge()
{
this.length=3;
this.width=4;
}
public double getArea()
{
return(this.length*this.width);
}
public double getCircumference()
{
return((this.length+this.width)*2);
}
public static void main(String args[])
{
Rectangle b=new Rectangle();
b.setEdge();
System.out.println("the area is "+b.getArea());
System.out.println("the circumference is "+b.getCircumference());
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
昨天听了一首歌曲,女生唱的,只记住一句歌词
判断污水浓度的高低的数值是多少
安米娜气垫CC霜涂上去脸会看起来油油的吗?求
柏乡中学副校长梁立营
离婚前办的信用卡欠款离婚另一方后需要负责吗
中国信合(春光分社)(内朝阳路与迎宾路交叉口
大莲塘村地址在哪,我要去那里办事
紫阳县蒿平镇有个韵达快递具体位置在哪
我冲动说了分手,都一个星期了,女朋友都不理
怎么删除鼠标右键不用的项
6年级英语句型
我现在想生产一套商品,有具体的制作方案,销
兔子一般 从小到大 什么时候才能生兔宝宝。
(a+1.5a)x6 梅2=60怎么解方程
求日剧非自然死亡百度云谢谢啦
推荐资讯
50克的黄金手镯和50克的银手镯,哪个粗
狗一兴奋就撒尿
DNF天空套的合出部位是随机的么,
神光三的实验室是研究什么的??介绍一下神光的
在南宁租房子住的各位们,能不能告诉下怎么给
三十五岁的女人脸上过敏了脸很干用淡盐水洗脸
PS里怎么打开 Sharpen Only Edges BH动作
四川广元苍溪到四川巴中最近公路
四川金强男篮6月16号的比赛在哪里举行?和门票
吉利金刚安装行车记录仪需要多少钱?
内蒙古赤峰有全峰快递麽
天舒空气能价格怎么样?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?