interface Stockable
{
void setNumber(int Number);
int getNumber();
void setWeight(double Weight);
double getWeight();
void setVolume(double Volume);
double getVolume();
void setDescription(String Description);
String getDescription();
double getFullWeight();
}
abstract class Freight implements Stockable
{
int Number;
double Weight,Volume,fullWeight;
String Description;
public void setNumber(int Number)
{
this.Number=Number;
}
public int getNumber()
{
return Number;
}
public void setWeight(double Weight)
{
this.Weight=Weight;
}
public double getWeight()
{
return Weight;
}
public void setVolume(double Volume)
{
this.Volume=Volume;
}
public double getVolume()
{
return Volume;
}
public void setDescription(String Description)
{
this.Description=Description;
}
public String getDescription()
{
return Description;
}
abstract public String toString();
abstract public double getFullWeight();
}
class Bricks extends Freight
{
Bricks(int Number, double Weight, double Volume, String Description) 
{
super();
this.Number = Number;
this.Weight = Weight;
this.Volume = Volume;
this.Description = Description;
}
public String toString()
{
System.out.println("Charge " + String.valueOf(this.getNumber()) +
       " (" + this.getVolume() + "m3 " + this.getFullWeight() + "t)");
return "Charge " + String.valueOf(this.getNumber()) +
       " (" + this.getVolume() + "m3 " + this.getFullWeight() + "t)\n";
}
public double getFullWeight()
{
return this.getWeight()*this.getVolume();
}
}
class Wood extends Freight
{
private boolean dry = true;
Wood(int Number, double Weight, double Volume, String Description, boolean dry) 
{
super();
this.setNumber(Number);
this.setWeight(Weight);
this.setVolume(Volume);
this.setDescription(Description);
this.dry=dry;
}
public String toString() 
{
System.out.println("Charge " + String.valueOf(this.getNumber()) +
       " (" + this.getVolume() + "m3 " + this.getFullWeight() + "t)");
return "Charge " + String.valueOf(this.getNumber()) +
       " (" + this.getVolume() + "m3 " + this.getFullWeight() + "t)\n";
}
public double getFullWeight() 
{
if (this.dry=true)
{
double fullWeight=this.getWeight()*this.getVolume()*1.2;
}
else fullWeight=this.getWeight()*this.getVolume();
return fullWeight;
}
}
class Oil extends Freight
{
boolean flammable;
Oil(int Number,double Weight,double Volume,String Description,boolean flammable)
{
super();
this.setNumber(Number);
this.setWeight(Weight);
this.setVolume(Volume);
this.setDescription(Description);
this.setFlammable(flammable);
}
public void setFlammable(boolean flammable)
{
this.flammable=flammable;
}
public boolean getFlammable()
{
return flammable;
}
public double getFullWeight()
{
return this.getWeight()*this.getVolume();
}
public String toString()
{
System.out.println("Charge " + String.valueOf(this.getNumber()) +
       " (" + this.getVolume()*1000 + "Liter " + this.getFullWeight()+ "t)");
return "Charge " + String.valueOf(this.getNumber()) +
       " (" + this.getVolume()*1000 + "Liter " + this.getFullWeight()+ "t)\n";
}
}
abstract class StockManager 
{
Stockable[] list;
double Capacity;

StockManager(double Capacity) 
{
this.Capacity = Capacity;
this.list = new Stockable[100];
}
public boolean stock(Stockable stockable) 
{
double volume = 0;
int i;
for (i=0; i < this.list.length; i++)
{
if (this.list[i] != null) 
{
volume += this.list[i].getVolume();
}
else
break;
}
    if (volume + stockable.getVolume() <= Capacity) 
   {
  this.list[i] = stockable;
  System.out.println( " -> wurde eingelagert.");
  System.out.println("TESTLADUNG: "+stockable.getDescription()+" wurden auf den Frachter verladen.\n");
  return true;
   }
   else
{
       System.out.println(stockable.getDescription() + " findet keinen Platz, Kapazit?t [m3]:"+this.Capacity);
   System.out.println("TESTLADUNG: "+stockable.getDescription()+" konnte nicht auf den Tanker verladen werden!\n");
       return false;
}
}
abstract void InvalidStockableException(Stockable s);
void InsufficientStockingSpaceException()
{
        double allVolume=0.0;
for (int i=0;i<this.list.length ;i++ )
{
allVolume=this.list[i].getVolume()+allVolume;
}
if (allVolume<=Capacity)
{
System.out.println("Insufficient stocking space!!");
}
}
}
class Freighter extends StockManager
{

Freighter(double Capacity)
{
       super(Capacity);
   
}
void InvalidStockableException(Stockable s)
{

  if (s.getDescription().indexOf("oil")!=-1)
  {
  System.out.println("passt nicht zum Schiffstyp Frachter!");
  System.out.println("TESTLADUNG: "+s.getDescription()+" konnten nicht auf den Frachter verladen werden!\n");
  }
}

}
class Tanker extends StockManager
{
Tanker(double Capacity)
{
super(Capacity);

}
void InvalidStockableException(Stockable s)
{

  if (s.getDescription().indexOf("stein")!=-1||s.getDescription().indexOf("wood")!=-1)
  {
  System.out.println("passt nicht zum Schiffstyp Tanker!");
  System.out.println("TESTLADUNG: "+s.getDescription()+" konnten nicht auf den Frachter verladen werden!\n");
  }
}

}
class Harbour
{
public static void main(String...args)
{
Freighter fr=new Freighter(1000.0);
Tanker ta=new Tanker(45.0);
Bricks br=new Bricks(124,0.9,800.0,"Ziegelsteine");
Oil oil=new Oil(123,0.778,50.0,"oil",true);
oil.getFullWeight();
oil.toString();
ta.InvalidStockableException(oil);
ta.stock(oil);
ta.InsufficientStockingSpaceException();
br.getFullWeight();
br.toString();
fr.InvalidStockableException(br);
fr.stock(br);
fr.InsufficientStockingSpaceException();
br.toString();
ta.InvalidStockableException(br);
oil.toString();
fr.InvalidStockableException(oil);;

}
}提示在 allVolume=this.list[i].getVolume()+allVolume;找不到零点值

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【sisi_pepsi】截止到2008-06-22 17:54:16的历史汇总数据(不包括此帖):
    注册日期:2008-6-4
    上次登录:2008-6-22
    发帖数:1                  发帖分:20                 
    结贴数:1                  结贴分:20                 
    结贴率:100.00%        结分率:100.00%        
    敬礼!
      

  2.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【sisi_pepsi】截止到2008-06-22 17:53:52的历史汇总数据(不包括此帖):
    发帖数:1                  发帖分:20                 
    结贴数:1                  结贴分:20                 
    结贴率:100.00    %        结分率:100.00    %        
    敬礼!
      

  3.   

    System.out.println(list);打印出list 的值看看
      

  4.   

    试过了,为什么是null呢?我已经给它赋值了呀
      

  5.   

    你认为在这里赋值了?没有吧
    public boolean stock(Stockable stockable) {
    double volume = 0;
    int i;
    for (i = 0; i < this.list.length; i++) {
    if (this.list[i] != null) {
    volume += this.list[i].getVolume();
    } else
    break;
    }
    if (volume + stockable.getVolume() <= Capacity) {
    this.list[i] = stockable;
    System.out.println(" -> wurde eingelagert.");
    System.out.println("TESTLADUNG: " + stockable.getDescription()
    + " wurden auf den Frachter verladen.\n");
    return true;
    } else {
    System.out.println(stockable.getDescription()
    + " findet keinen Platz, Kapazit?t [m3]:" + this.Capacity);
    System.out.println("TESTLADUNG: " + stockable.getDescription()
    + " konnte nicht auf den Tanker verladen werden!\n");
    return false;
    }
    }
      

  6.   


    class Oil extends Freight 

    boolean flammable; 
    Oil(int Number,double Weight,double Volume,String Description,boolean flammable) 

    super(); 
    this.setNumber(Number); 
    this.setWeight(Weight); 
    this.setVolume(Volume); 
    this.setDescription(Description); 
    this.setFlammable(flammable); 

    public void setFlammable(boolean flammable) 

    this.flammable=flammable; 

    public boolean getFlammable() 

    return flammable; 

    public double getFullWeight() 

    return this.getWeight()*this.getVolume(); 

    public String toString() 

    System.out.println("Charge " + String.valueOf(this.getNumber()) + 
          " (" + this.getVolume()*1000 + "Liter " + this.getFullWeight()+ "t)"); 
    return "Charge " + String.valueOf(this.getNumber()) + 
          " (" + this.getVolume()*1000 + "Liter " + this.getFullWeight()+ "t)\n"; 

    } LZ发现没,你这个类里面没有getVolume()和getWeight()方法,应该是调用父类的方法吧
    要用super吧.
      

  7.   

    这个应该是对的,我没有重写父类的方法,只是继承,所以调用的话可以用this的