java编程题 ,求高手帮忙
1创建一个Rectangle类,添加2个属性width、height。2在Rectangle中添加2个方法计算矩形的周长和面积。3编程利用Rectangle类的对象输出一...
1创建一个Rectangle类,添加2个属性width、height。
2在Rectangle中添加2个方法计算矩形的周长和面积。
3编程利用Rectangle类的对象输出一个矩形的周长和面积。 展开
2在Rectangle中添加2个方法计算矩形的周长和面积。
3编程利用Rectangle类的对象输出一个矩形的周长和面积。 展开
2个回答
展开全部
public class Rectangle {
private double width;
private double height;
public Rectangle(){
}
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public static void main(String[] args) {
Rectangle r = new Rectangle(3, 4);
System.out.println( "长为3,宽为4得长方形面积为:"+ r.area());
System.out.println( "长为3,宽为4得长方形周长为:"+ r.perimeter());
}
public double area(){
return width * height;
}
public double perimeter(){
return 2 * (width + height);
}
}
private double width;
private double height;
public Rectangle(){
}
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public static void main(String[] args) {
Rectangle r = new Rectangle(3, 4);
System.out.println( "长为3,宽为4得长方形面积为:"+ r.area());
System.out.println( "长为3,宽为4得长方形周长为:"+ r.perimeter());
}
public double area(){
return width * height;
}
public double perimeter(){
return 2 * (width + height);
}
}
展开全部
public class Rectangle {
private double width;
private double height;
publice double getWidth(){
return this.width;
}
publice voidsetWidth(double width){
return this.width=width;
}
publice double getHeight(){
return this.width;
}
publice void getHeight(double height){
this.width=height
}
public Rectangle(){ }
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public double area(){
return width * height;
}
public double perimeter(){
return 2 * (width + height);
}
}
请养成良好的编程习惯
private double width;
private double height;
publice double getWidth(){
return this.width;
}
publice voidsetWidth(double width){
return this.width=width;
}
publice double getHeight(){
return this.width;
}
publice void getHeight(double height){
this.width=height
}
public Rectangle(){ }
public Rectangle(double width, double height){
this.width = width;
this.height = height;
}
public double area(){
return width * height;
}
public double perimeter(){
return 2 * (width + height);
}
}
请养成良好的编程习惯
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询