java创建一个矩形类,属性包括原点坐标(x,y),长度和宽度
构造函数:直接构造原点坐标、长度、宽度方法:求矩形的面积编程实现:构造两个矩形:1。原点在(0.10),长度为10,宽度为20求它的面积2。原点在(20.10),长度为1...
构造函数:直接构造原点坐标、长度、宽度
方法:求矩形的面积
编程实现:
构造两个矩形:1。原点在(0.10),长度为10,宽度为20 求它的面积
2。原点在(20.10),长度为10,宽度为20 求它的面积 展开
方法:求矩形的面积
编程实现:
构造两个矩形:1。原点在(0.10),长度为10,宽度为20 求它的面积
2。原点在(20.10),长度为10,宽度为20 求它的面积 展开
展开全部
import java.util. * ;
public class Rectangle {
private int x; // 原点横坐标
private int y; // 纵坐标
private int length; //定义长变量
private int width; // 宽变量
public Rectangle(int x, int y, int length, int width) {
this.x = x;
this.y = y;
this.length = length;
this.width = width;
}
public int getArea() { //求面积方法
return length * width;
}
public static void main(String[] args) {
System.out.println("矩形0,10的面积:" + new Rectangle(0, 10, 10, 20).getArea());
System.out.println("矩形20,10的面积为:" + new Rectangle(20, 10, 10, 20).getArea());
}
}
展开全部
package BaseExec;
public class JudgeRec {
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle r1 = new Rectangle(0,10,10,20);
Rectangle r2 = new Rectangle(20,10,10,20);
r1.showArea();
r2.showArea();
}
}
class Rectangle{
private double x;
private double y;
private double length;
private double width;
public Rectangle(double x, double y,double length, double width){
this.x = x;
this.y = y;
this.length = length;
this.width = width;
}
public void showArea(){
System.out.println("面积是" + width * length);
}
}
public class JudgeRec {
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle r1 = new Rectangle(0,10,10,20);
Rectangle r2 = new Rectangle(20,10,10,20);
r1.showArea();
r2.showArea();
}
}
class Rectangle{
private double x;
private double y;
private double length;
private double width;
public Rectangle(double x, double y,double length, double width){
this.x = x;
this.y = y;
this.length = length;
this.width = width;
}
public void showArea(){
System.out.println("面积是" + width * length);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Rectangle {
int x;
int y;
int length;
int width;
public Rectangle(int x, int y, int length, int width) {
this.x = x;
this.y = y;
this.length = length;
this.width = width;
}
public void getArea(){
System.out.println(length*width);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询