读书人

2009年5月程序员笔试考前练习(24)

发布时间: 2010-10-25 15:57:58 作者: kind887

读书人IT频道reader8.net/exam/jisuanji/   阅读以下说明和Java程序,将应填入__(n)__处的字句写在答题纸的对应栏内
  【说明】
  以下程序的功能时三角形、矩形和正方形的面积输出。
  程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。
  【程序】
  public class areatest{
  public static viod main(string args[]){
    Figure[]Figures={
     New Triangle(2,3,3),new rectangle(5,8),new square(5)
    };
    for (int i= 0;i< Figures.length;i++){
     system.out.println(Figures+”area=”+ Figures.getarea());
    }
  }
  }
  public abstract class figure{
  public abstract double getarea();
  }
  public class rectangle extends __(1)__ {
  double height;
  double width;
  public rectangle (double height, double width){
    this.height= height;
    this. width = width;
  }
  public string tostring(){
    return”rectangle: height=”+ height +”, width=”+ width +”:”;
  }
  public double getarea(){
    return __(2)__
  }
  }
  public class square exends __(3)__
  {
  public square(double width) {
    __(4)__ ;
  }
  public string tostring(){
    return” square:width=”+width”:”;
  }
  }
  public class rectangle entend __(5)__
  {
  double la;
  double lb;
  double lc;
  public triangle(double la ,double lb,double lc){
    this.la=la; this.lb=lb; this.lc=lc;
  }
  public string tostring(){
    return” triangle:sides=”+la+”, ”+lb+”, ”+lc+”:”;
  }
  public double get area(){
    double s=(la+lb+lc)/2.0;
    return math.sqrt(s*(s-la) *(s-lb) *(s-lc));
  }
  }
  答案:
   (1)Figure
   (2)height*width
   (3)Rectangle
   (4)super(width,width)
   (5)Figurewww.Exam8.CoM 读书人IT频道reader8.net/exam/jisuanji/
读书人网 >初级职称

热点推荐