Ladder
package com.hanqi.test;
public class Ladder {
//属性
double shangdi,xiadi,gao,mianji;
//构造方法
Ladder(double sd,double xd,double g)
{
shangdi=sd;
xiadi=xd;
gao=g;
mianji=(sd+xd)*g/2;
}
//成员方法
//返回面积
//返回类型 方法名(参数列表)
double getMianJi()
{
//返回语句
return mianji;
}
}
Circle
package com.hanqi.test;
public class Circle {
double banjing,zhouchang,mianji;
Circle(double r)
{
banjing=r;
zhouchang=2Math.PIr;
mianji=Math.PIrr;
}
double getZhouChang()
{
return zhouchang;
}
double getMianJi()
{
return mianji;
}
}
主类
package com.hanqi.test;
public class Test03 {
public static void main(String[] args) {
//实例化
Ladder l1=new Ladder (10,20,5);
//得到面积
System.out.println(l1.getMianJi());
l1=new Ladder(1,3,20);
System.out.println(l1.getMianJi());
Circle l2=new Circle(5);
System.out.println(l2.getZhouChang());
System.out.println(l2.getMianJi());
}
}