如何用java编写矩形的平移和旋转后输出坐标的代码
1个回答
展开全部
class Rectangle{
double x1, y1, x2, y2;
Rectangle(){
this(0,0,0,0);
}
Rectangle(double x1, double y1, double x2, double y2){
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
double getArea(){
return Math.abs((x1-x2)*(y1-y2))/2;
}
double getPemi(){
return Math.abs((x1-x2)+(y1-y2))*2;
}
}
public class Test{
public static void main(String[] args) {
Rectangle a = new Rectangle();
a.x1=2.1;
a.y1=3.2;
a.x2=5.2;
a.y2=6.3;
System.out.println("面积是"+a.getArea()+" 周长是"+a.getPemi());
Rectangle b = new Rectangle(1, 2, 6.8, 10.5);
System.out.println("面积是"+b.getArea()+" 周长是"+b.getPemi());
}
}
double x1, y1, x2, y2;
Rectangle(){
this(0,0,0,0);
}
Rectangle(double x1, double y1, double x2, double y2){
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
double getArea(){
return Math.abs((x1-x2)*(y1-y2))/2;
}
double getPemi(){
return Math.abs((x1-x2)+(y1-y2))*2;
}
}
public class Test{
public static void main(String[] args) {
Rectangle a = new Rectangle();
a.x1=2.1;
a.y1=3.2;
a.x2=5.2;
a.y2=6.3;
System.out.println("面积是"+a.getArea()+" 周长是"+a.getPemi());
Rectangle b = new Rectangle(1, 2, 6.8, 10.5);
System.out.println("面积是"+b.getArea()+" 周长是"+b.getPemi());
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询