用JAVA编写程序,编写一个Rect类 ,要求,(1)Rect类的私有成员变量有:a:double型,代表长 b: doubl

(1)Rect类的私有成员变量有:
a:double型,代表长
b: double型,代表宽
(2)Rect类的共有成员有:
Rect():构造方法。默认的ab值都为零。
Rect(double len,double width):分别用两个形势lenm width对成员变量a b进行初始化。
Double area():计算矩形面积。
Void display():输出矩形的长,宽。和面积。
(3)然后编写一个含有main()方法的类userect,创建Rect类的对象,并调用上面的定义的方法(参数值自行定义)

谢谢各位高手咯,杂看不懂这题。谢谢诶。标注的也清楚写哦

class Rect{
private double a ;
private double b;

Rect(){
this.a = 0;
this.b = 0;
}
Rect(double len,double width){
this.a = len;
this.b = width;
}

public Double area(){
return this.a* this.b;
}
public void display(){
System.out.println(this.area());
}
}
public class userect {

public static void main(String[] args){
Rect rect1 = new Rect();
rect1.display();

Rect rect2 = new Rect(10,10);
rect2.display();
}

}
温馨提示:内容为网友见解,仅供参考
无其他回答

...要求,(1)Rect类的私有成员变量有:a:double型,代表长 b: doubl...
public class userect { public static void main(String[] args){ Rect rect1 = new Rect();rect1.display();Rect rect2 = new Rect(10,10);rect2.display();} }

Java 编写一个矩形类Rect
public class Rect { private double length;\/\/矩形的长 private double width;\/\/矩形的宽 public Rect() {}\/\/默认构造器 public Rect(double length,double width) { this.length = length;this.width = width;} \/ 取得矩形的面积 \/ public double getArea(){ return this.getLength() * this....

编写一个Rect类 在线等
public Rect() { this.a = 0;this.b = 0;} public Rect(double len,double width) { this.a = len;this.b = width;} public double area() { return a*b;} void display() { System.out.println("长方形的长:"+a+"长方形的宽:"+b);System.out.println("长方形的面积:"+are...

设计一个类Rect, 该类中的私有成员变量为表示Rect的长和宽和周长
Rect a;a.setLength(20);a.setWidth(20);cout<<a.permi()<<endl;cin.get();return 0;}

...1.按以下要求编写程序(1) 创建一个Rectangle类,添加width和height两...
} public double getPerimeter() { return (width + height) * 2;} } public class App { public static void main(String[] args) { Rectangle rect = new Rectangle(50, 20);System.out.println("矩形,面积:" + rect.getArea() + ",周长:" + rect.getPerimeter());} } ...

怎样用java设计一个成员变量包括长和宽的长方形类并计算面积和周长...
class Test {\\x0d\\x0a public static void main(String[] args){\\x0d\\x0a Rectangle rect = new Rectangle(2,3);\\x0d\\x0a System.out.println("长方形的宽 :" + rect.getWidth());\\x0d\\x0a System.out.println("长方形的高 :" + rect....

Java定义长方形类Rect ,包含三个属性长len ,宽width,高height和一个计算...
public void setHeight(double height) { this.height = height;} } class RectTest { public static void main(String[] args) { Rect rect = new Rect();rect.setLen(5);rect.setWidth(7);rect.setHeight(9);double volume = rect.volume();System.out.println("体积为 = " + volume)...

在JAVA Eclipse环境中,定义创建一个Rectabgle类,包括两个属性,weight和...
perimeter(){return (weight+height)*2;}public double area(){return weight*height;}}public class Test {public static void main(String[] args) {Rectangle rect=new Rectangle(3, 4);System.out.println("周长:"+rect.perimeter());System.out.println("面积:"+rect.area());}} ...

Java编写一个矩形类,并计算面积和周长?
class Rectangle{ private int width = 2;private int length = 1;public int getWidth(){ return this.width;} public void setWidth(int w){ this.width = w;} public int getLength(){ return this.length;} public void setLength(int l){ this.length = l;} public int getArea(){ ...

1. 设计并实现一个类Rectangle(正方形
代码如下:include <iostream>#include <string>using namespace std; class Rectangle { public: Rectangle() : length(length), width(width), color("") {} int GetLength() { return this->length; } void SetLength(int length) { this->length = length; } int...

相似回答