求园柱体的表面积和体积

1.先创建一个Point类,然后定义Trianglele类。在Trianglele类中定义三个Point的实体来表示一个三角形的三个点,再定义一个方法setTri对这三个点进行初始化,然后定义两个方法求三角形的周长、面积。在main()中创建一个对象,求给定三点的三角形的周长、面积。
2.将上题的方法setTri改用构造方法实现初始化。
3.编写JAVA程序求园柱体的表面积和体积,已知底面圆心p为(0,0),半径r为10,圆柱体高5。 
第一题:
public class Trianglele {
 Point p1 = new Point();
 Point p2 = new Point();
 Point p3 = new Point();

 void setTri(double x1, double y1, double x2, double y2, double x3, double y3) {
  this.p1.x = x1;
  this.p1.y = y1;
  this.p2.x = x1;
  this.p1.y = y2;
  this.p3.x = x3;
  this.p3.y = y3;
 }

 double Circumference(Trianglele t) {
  double line1, line2, line3;
  line1 = Math.hypot((t.p1.x - t.p2.x), (t.p1.y - t.p2.y));
  line2 = Math.hypot((t.p2.x - t.p3.x), (t.p2.y - t.p3.y));
  line3 = Math.hypot((t.p1.x - t.p3.x), (t.p1.y - t.p3.y));
  return line1 + line2 + line3;
 }
 
 double Area(Trianglele t) {
  double line1, line2, line3;
  line1 = Math.hypot((t.p1.x - t.p2.x), (t.p1.y - t.p2.y));
  line2 = Math.hypot((t.p2.x - t.p3.x), (t.p2.y - t.p3.y));
  line3 = Math.hypot((t.p1.x - t.p3.x), (t.p1.y - t.p3.y));
  double p = Circumference(t)/2;
  return Math.sqrt((p-line1)*(p-line2)*(p-line3)*p);
 }
 public static void main(String[] args) {
  Trianglele t =new Trianglele();
  t.setTri(0, 0, 0, 3, 4, 0);
  System.out.println("三角形周长:"+t.Circumference(t));
  System.out.println("三角形面积:"+t.Area(t));
 }

}

class Point {
 double x, y;
} 

第二题:
public class Trianglele {
 Point p1 = new Point();
 Point p2 = new Point();
 Point p3 = new Point();

 Trianglele(double x1, double y1, double x2, double y2, double x3, double y3) {
  this.p1.x = x1;
  this.p1.y = y1;
  this.p2.x = x1;
  this.p1.y = y2;
  this.p3.x = x3;
  this.p3.y = y3;
 }

 double Circumference(Trianglele t) {
  double line1, line2, line3;
  line1 = Math.hypot((t.p1.x - t.p2.x), (t.p1.y - t.p2.y));
  line2 = Math.hypot((t.p2.x - t.p3.x), (t.p2.y - t.p3.y));
  line3 = Math.hypot((t.p1.x - t.p3.x), (t.p1.y - t.p3.y));
  return line1 + line2 + line3;
 }
 
 double Area(Trianglele t) {
  double line1, line2, line3;
  line1 = Math.hypot((t.p1.x - t.p2.x), (t.p1.y - t.p2.y));
  line2 = Math.hypot((t.p2.x - t.p3.x), (t.p2.y - t.p3.y));
  line3 = Math.hypot((t.p1.x - t.p3.x), (t.p1.y - t.p3.y));
  double p = Circumference(t)/2;
  return Math.sqrt((p-line1)*(p-line2)*(p-line3)*p);
 }
 public static void main(String[] args) {
  Trianglele t =new Trianglele(0, 0, 0, 3, 4, 0);
  System.out.println("三角形周长:"+t.Circumference(t));
  System.out.println("三角形面积:"+t.Area(t));
 }

}

class Point {
 double x, y;
} 

第三题:
public class Cylinder {
 double radius,height;
 public static void main(String[] args) {
  Cylinder c = new Cylinder();
  System.out.println("圆柱体体积:"+c.Volume(10, 5));

 }
 double Volume(double r,double h) {
  return 3.14*r*r*h;
 }
 
} 

 

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值