//三角形
public class Triangle
{
public static void main(String[] args)
{
CTriangle c = new CTriangle(3,4,5);
System.out.println("三角形的面积是:"+c.area()+" 三角形的周长是: "+c.perimeter());
}
}
class CTriangle{
float x,y,z,p,are,per;
CTriangle(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
public void set_x(int x)
{
this.x = x;
}
public void set_y(int y)
{
this.y = y;
}
public void set_z(int z)
{
this.z = z;
}
public float area()//计算面积
{
p = (x + y + z) / 2.0f;
are = (float)Math.sqrt(p * (p - x) * (p - y) * (p - z));
return are;
}
public float perimeter()//求周长
{
return (per = x + y + z);
}
}
///圆形
public class Circular
{
public static void main(String[] args)
{
CCircular c = new CCircular(5);
System.out.println("圆的面积是:"+c.area()+" 圆的周长是: "+c.perimeter());
}
}
class CCircular
{
float r;//这是圆的半径
CCircular(float r)
{
this.r = r;
}
public void set_r(float r)
{
this.r = r;
}
public float area()//计算面积
{
return (r* 3.14f * r );
}
public float perimeter()//求周长
{
return (2.0f * 3.14f * r);
}
}