java吧 关注:1,296,365贴子:12,831,479
  • 2回复贴,共1

各位帮看下为什么运行不了?

取消只看楼主收藏回复

interface ComputerWeight
{  public double computerWeight();
}
class Television implements ComputerWeight
{  public double computerWeight()
  {
return 50;
}
}
class Computer implements ComputerWeight
{public double computerWeight(){
return 45;
}}
class WashMachine implements ComputerWeight
{  public double computerWeight(){
return 30;
}
}
class Car
{  ComputerWeight[] goods;
   double totalWeight=0;
   Car(ComputerWeight[] goods)
   { this.goods=goods;
   }
   public double getTotalWeight()
   {  totalWeight=0;
      for(int i=0;i<goods.length;)
      {totalWeight=totalWeight+goods[i].computerWeight();      
      
      }return totalWeight;
   }
}
public class Road 
{  public static void main(String args[])
   {  ComputerWeight[] goodsOne=new ComputerWeight[50],
                   goodsTow=new ComputerWeight[22];
   for(int i=0;i<goodsOne.length;i++)
   {  if(i%3==0)
   goodsOne[i]=new Television();
   else if(i%3==1)
   goodsOne[i]=new Computer();
   else if(i%3==2)
   goodsOne[i]=new WashMachine();
   }
   for(int i=0;i<goodsTow.length;i++)
   {  if(i%3==0)
   goodsTow[i]=new Television();
   else if(i%3==1)
   goodsTow[i]=new Computer();
   else if(i%3==2)
   goodsTow[i]=new WashMachine();
   }
   Car 大货车=new Car(goodsOne);
   System.out.println("大货车装载的货物重量:"+大货车.getTotalWeight());
   Car 小货车=new Car(goodsTow);
   System.out.println("小货车装载的货物重量:"+小货车.getTotalWeight());
   
   }
}


1楼2009-10-18 21:39回复
    新手,见谅


    2楼2009-10-18 21:42
    回复
      2026-01-31 01:36:52
      广告
      不感兴趣
      开通SVIP免广告
      疏忽了。谢谢。


      4楼2009-10-18 22:29
      回复