跪求一道JAVA题目
编写类Rectangle:属性:width(矩形的宽度)、height(矩形的长度)方法:构造方法:Rectangle(doublew,doubleh)求矩形的面积:do...
编写类Rectangle:
属性:width(矩形的宽度)、height(矩形的长度)
方法:
构造方法:Rectangle(double w,double h)
求矩形的面积:double getArea(double w,double h)
求矩形的周长:double getPerimeter(double w,double h)
输出矩形描述信息:void display()
结果如 width=1.0,height=2.0,area=2.0,perimeter=6.0
编写测试类RectangleTest进行测试:
创建Rectangle对象,计算面积和周长,并输出对象的描述信息。 展开
属性:width(矩形的宽度)、height(矩形的长度)
方法:
构造方法:Rectangle(double w,double h)
求矩形的面积:double getArea(double w,double h)
求矩形的周长:double getPerimeter(double w,double h)
输出矩形描述信息:void display()
结果如 width=1.0,height=2.0,area=2.0,perimeter=6.0
编写测试类RectangleTest进行测试:
创建Rectangle对象,计算面积和周长,并输出对象的描述信息。 展开
展开全部
import java.lang.*;
public class Rectangle {
public Rectangle(double w, double h){
this.width = w;
this.height = h;
}
public double getArea(double w, double h){
return w*h;
}
public double getPerimeter(double w, double h){
return 2*(w + h);
}
public void display(){
System.out.print("width="+this.width);
System.out.print(",height="+this.height);
System.out.print(",area="+getArea(this.width, this.height));
System.out.print(",perimeter="+getPerimeter(this.width, this.height));
}
private double width;
private double height;
public static void main(String argv[]){
Rectangle r = new Rectangle(1.0, 2.0);
r.display();
}
}
public class Rectangle {
public Rectangle(double w, double h){
this.width = w;
this.height = h;
}
public double getArea(double w, double h){
return w*h;
}
public double getPerimeter(double w, double h){
return 2*(w + h);
}
public void display(){
System.out.print("width="+this.width);
System.out.print(",height="+this.height);
System.out.print(",area="+getArea(this.width, this.height));
System.out.print(",perimeter="+getPerimeter(this.width, this.height));
}
private double width;
private double height;
public static void main(String argv[]){
Rectangle r = new Rectangle(1.0, 2.0);
r.display();
}
}
展开全部
public class Rectangle {
private double width=0.0;//(矩形的宽度)、height(矩形的长度)
private double height=0.0;
public Rectangle(double w,double h){
width =w;
height =h;
}
public double getArea(double w,double h){
return w*h;
}
public double getArea(){
return width*height;
}
public double getPerimeter(double w,double h){
return w*2+h*2;
}
public double getPerimeter(){
return width*2+height*2;
}
public void display(){
System.out.println("如果width="+width+" height="+height+" area="+getArea()+" Perimeter="+getPerimeter());
}
}
public class ectangleTest {
public static void main(String args[]){
Rectangle rectangle = new Rectangle(15.2,11.3);
rectangle.display();
}
}
private double width=0.0;//(矩形的宽度)、height(矩形的长度)
private double height=0.0;
public Rectangle(double w,double h){
width =w;
height =h;
}
public double getArea(double w,double h){
return w*h;
}
public double getArea(){
return width*height;
}
public double getPerimeter(double w,double h){
return w*2+h*2;
}
public double getPerimeter(){
return width*2+height*2;
}
public void display(){
System.out.println("如果width="+width+" height="+height+" area="+getArea()+" Perimeter="+getPerimeter());
}
}
public class ectangleTest {
public static void main(String args[]){
Rectangle rectangle = new Rectangle(15.2,11.3);
rectangle.display();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编写一个简单的JAVA程序 要求:以矩形为对象,求一个矩形的周长与面积
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询