pen类拥有的属性:笔尖的粗细、墨水量、墨水颜色、有无笔帽、长度及半径。
pen类拥有的方法:画图、写字、更换墨水。
public class Pen
{
public static void main(String[] args)
{
aa a1=new aa();
a1.huatu("细","满","蓝色",true);
a1.xiezi(10,1.5);
a1.moshui("黑色");
}
}
class aa
{
String bijian;
String rongliang;
String yanse;
boolean bimao;
int height;
double witch;
void huatu(String bijian,String rongliang,String yanse,boolean bimao)
{
this.bijian=bijian;
this.rongliang=rongliang;
this.yanse=yanse;
this.bimao=bimao;
System.out.println("笔尖粗细为:"+bijian);
System.out.println("容量为:"+rongliang);
System.out.println("颜色为:"+yanse);
if(bimao==true)
{
System.out.println("有笔帽");
}
else
{
System.out.println("无笔帽");
}
System.out.println("画图");
}
void xiezi(int height,double witch)
{
System.out.println("长度为:"+height);
System.out.println("半径为:"+witch*height/2);
System.out.println("写字");
}
void moshui(String yanse)
{
System.out.println("更换颜色为:"+yanse);
}
}