封装类-圆形和梯形面积

 1 package com.hanqi.z1p1;
 2 
 3 public class Lader {
 4 
 5     double Shang;
 6     double Xia;
 7     double Height;
 8     double Slader;
 9      
10     Lader(double sh,double xi,double gao)
11     {
12         Shang=sh;
13         Xia=xi;
14         Height=gao;
15         Slader=(Shang+Xia)*Height/2;
16         System.out.println("梯形的面积是:"+Slader);
17     }
18     
19     
20 }
 1 package com.hanqi.z1p1;
 2 
 3 public class Circle {
 4 
 5     double r;
 6     double l;
 7     double Scircle;
 8     final double PAI=3.14;
 9     
10     Circle(double banjing)
11     {
12         r=banjing;
13         l=2*PAI*r;
14         Scircle=PAI*r*r;
15         System.out.println("圆形的周长是:"+l+",圆形的面积是:"+Scircle);
16     }
17     
18     
19 }
 1 package com.hanqi.z1p1;
 2 
 3 public class Homework0516 {
 4 
 5     public static void main(String[] args) {
 6         // TODO 自动生成的方法存根
 7 
 8 
 9         //测试类Lader和类Circle的功能。
10         
11         Lader tixing=new Lader(5.0,8.0,6.0);
12         
13         Circle yuan=new Circle(3.0);
14         

 

运行结果:

posted @ 2016-05-17 08:23  鱼在我这里  阅读(266)  评论(0编辑  收藏  举报