A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 邱峁 中级黑马   /  2012-12-10 16:41  /  1004 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


class MyShape
{
private double m_hou;

public MyShape()
{
m_hou = 0.1;
}

public MyShape(double x)
{
m_hou = x;
}

public double getTiJi()
{
return getMianJi() * m_hou;
}

public double getMianJi()
{
return 0;
}
}

class Circle extends MyShape
{
private double m_r;

public Circle(double r, double hou)
{
super(hou);
m_r = r;
}

public Circle(double r)
{
m_r = r;
}

public double getMianJi()
{
return Math.PI * m_r * m_r;
}
}

class Rect extends MyShape
{
private double m_a; // 长
private double m_b; // 宽

public Rect(double a, double b)
{
m_a = a;
m_b = b;
}

public Rect(double a)
{
m_a = a;
m_b = a;
}

public double getMianJi()
{
return m_a * m_b;
}
}


class Triangle extends MyShape
{
private double m_a; // 三边长
private double m_b; //
private double m_c; //

public Triangle(double a, double b, double c, double hou)
{
super(hou);
m_a = a;
m_b = b;
m_c = c;
}

public double getMianJi()
{
double s = (m_a+m_b+m_c)*0.5;
return Math.sqrt(s*(s-m_a)*(s-m_b)*(s-m_c));
}
}


public class MuXing
{
public static void main(String[] args)
{
MyShape[] x = new MyShape[5];

x[0] = new Circle(2.5, 0.5); // 半径,厚度
x[1] = new Circle(2.5);
x[2] = new Rect(2.5,1.5); // 长,宽
x[3] = new Triangle(2,3,4,0.1); // 三边,厚度
x[4] = new Rect(4); // 方形

double sum = 0;
for(int i=0; i<x.length; i++){
sum += x[i].getTiJi();
}

System.out.println(sum);
}
}

评分

参与人数 1技术分 +1 收起 理由
古银平 + 1 很给力!

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马