abstract class Shape
{
 double width,height;
 abstract double area(double width,double height);
}
class Triangle extends Shape
{
double width,height;
public void Triangle(double width,double height)
{
this.height=height;
this.width=width;
}
public double area(double width,double height)
{
return (width*height)/2;
}

}
class Rectangle extends Shape
{
double width,height;
public void Rectangle(double width,double height)
{
this.height=height;
this.width=width;
}
public  double  area(double width,double height)
{
return width*height;
}
}
 class shangJiZuoYe2 
{
 public static double calculateArea(Shape s)
 {
  double t1,t2;
  t1 = s.width;
  t2 = s.height;
return a.area(t1*t2); //这个地方有点问题。
 }
 public static void main(String []args)
 {
 Triangle a=new Triangle();
 a.Triangle(2.0,3.0);
 Rectangle b=new Rectangle();
 b.Rectangle(3.0,4.0);
 calculateArea(a);
 calculateArea(b);  
 }
}

解决方案 »

  1.   

     
    return a.area(t1*t2);    //这个地方有点问题。a是什么? 没有看到你定义a这个变量呀.
      

  2.   

    你在使用a之前没有定义,应该是s吧
    还有,shangJiZuoYe2,你的类名太强了:上机作业
    .....
      

  3.   

    return a.area(t1*t2);    
    改成return s.area(t1*t2); 眼花了吧。
      

  4.   

     return a.area(t1*t2);    //这个地方有点问题。
    应写成:return s.area(t1,t2);还有最重要的:
    Triangle 类和Rectangle 类都不应该再定义变量width和height。因为Shape类已经有了,子类再定义的话就把值给覆盖了。
    建议:
    把这两个类中
    double width,height;
    去掉!