1.设计图形(Shape)类及其子类(Circle、Rectangle、Triangle)。。。

更新时间:2023-07-08 09:41:02 阅读: 评论:0

leave
1.设计图形(Shape)类及其⼦类(Circle、Rectangle、
Triangle)。。。
Point:
public class Point {
private int x;
深圳城市学院private int y;
public int getX() {
return x;
beaujolais nouveau
}
public void tX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void tY(int y) {
this.y = y;
}
public Point() {
super();
}
}
Shape:
public class Shape {
private Point p;
private String color;
public double calcArea() {
return 0;
}
public double calcPerimeter() {
工程档案管理
return 0;
}
public Shape() {
super();
}
public Point getP() {
return p;
}
public void tP(Point p) {
this.p = p;
}
public String getColor() {
return color;
}
public void tColor(String color) {
}
}
Circle :
public class Circle extends Shape { private int radius;
public Circle() {
super();
}
public Circle(int radius) {
super();
this.radius = radius;
}
public double calcArea() {
return Math.PI * radius * radius;  }
public double calcPerimeter() {
return 2 * Math.PI * radius;
}
public int getR() {
return radius;
}
public void tR(int r) {
英语笑话大全 爆笑
this.radius = r;
}
}
Rectangle:
private int width;
public Rectangle() {
super();
}
public Rectangle(int length, int width) {  super();
this.length = length;
this.width = width;
}
public double calcArea() {
return length * width;
}
public double calcPerimeter() {
return 2 *( length + width);
}
public int getLength() {
return length;
}
public void tLength(int length) {
this.length = length;
occupywallstreet}
public int getWidth() {
return width;
}
in additionpublic void tWidth(int width) {
this.width = width;
}
}
Triangle:
private int height;
public Triangle() {
super();
}冲账
public Triangle(int length, int height) {
super();
this.length = length;
this.height = height;
}
public double calcArea() {alexandra stan
return  (length * height)/2;
}
public double calcPerimeter() {
return length +2 *Math.sqrt(((length/2)*(length/2))+(height* height)); }
public int getLength() {
return length;
}
public void tLength(int length) {意大利英文
this.length = length;
}
public int getHeight() {
return height;
}
public void tHeight(int height) {
this.height = height;
}
}
测试:Test
public class Testlianxi1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape s = new Shape();
Circle c = new Circle(5);
System.out.println("圆的⾯积为:" +c.calcArea());
System.out.println("圆的周长为:" +c.calcPerimeter());
Rectangle r = new Rectangle(5, 6);
System.out.println("矩形的⾯积为:" +r.calcArea());
System.out.println("矩形的周长为:" +r.calcPerimeter());
Triangle t = new Triangle(6, 4);
System.out.println("等腰三⾓形的⾯积为:" +t.calcArea());
System.out.println("等腰三⾓形的周长为:" +t.calcPerimeter()); }
}

本文发布于:2023-07-08 09:41:02,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/170875.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:深圳   设计   档案管理   笑话   矩形   学院   图形   工程
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图