資源簡介
SSD1【Unit3】答案【Exercise8,Practical Quiz 8】

代碼片段和文件信息
import?java.util.Vector;
/**
?*?Catfish?-?simulates?a?catfish?-?can?swim?eat?and?consume?
?*?energy?in?the?process.
?*?
?*?@author?A?JiaYi
?*?Created?on?Jul?5?2003
?*/
public?class?Catfish?extends?Animal?{
/**
?*?Energy?needed?to?swim?in?a?block?of?time.
?*/
private?static?final?int?ENERGY_TO_SWIM?=?2;
/**
?*?Energy?needed?to?look?for?food?once.
?*/
private?static?final?int?ENERGY_TO_LOOK_FOR_FOOD?=?1;
/**
?*?Lowest?possible?energy?needed?for?a?baby?to?survive.?
?*/
private?static?final?int?BABY_MIN_ENERGY?=?15;
/**
?*?Maximum?energy?that?a?baby?can?store.?
?*/
private?static?final?int?BABY_MAX_ENERGY?=?100;
/**
?*?Eenrgy?increment
?*/
private?static?final?int?ENERGY_INCREMENT?=?2;
/**
?*?Name?of?species
?*/
private?static?final?String?SPECIES?=?“Catfish“;
/**
?*?
?*?Number?of?Catfish?created
?*/
private?static?int?nCatfishCreated?=?0;?
/**
?*?Energy?expended?to?eat?once.
?*/
private?static?final?int?ENERGY_TO_EAT?=?1;
/**
?*?Energy?gained?when?a?full?meal?is?eaten.
?*/
private?static?final?int?ENERGY_IN_A_FULL_MEAL?=?10;
/**
?*?Constructor.?Initialize?an?algae?to?start?life?at?a?specified?
?*?location?with?a?specified?energy.?If?location?is?out?of?bounds
?*?locate?the?catfish?at?the?nearest?edge.
?*?
?*?@param?initialRow?-?the?row?at?which?the?catfish?is?located
?*?@param?initialColumn?-?the?column?at?which?the?catfish?is?located
?*?@param?initialSimulation?-?the?simulation?that?the?catfish?belongs?to
?*/
public?Catfish(
int?initialRow
int?initialColumn
Simulation?initialSimulation)?{
super(
initialRow
initialColumn
initialSimulation
SPECIES?+?nCatfishCreated
BABY_MIN_ENERGY
BABY_MAX_ENERGY);
++nCatfishCreated;
}
/**
?*?This?individual?belongs?to?the?Catfish?species.
?*??
?*?@return?The?string?indicating?the?species
?*/
public?String?getSpecies()?{
return?SPECIES;
}
/**
?*?Catfish?should?be?displayed?as?an?image.
?*?
?*?@return?a?constant?defined?in?{@link?Simulation#IMAGE?Simulation}?class
?*/
public?String?getDisplayMechanism()?{
return?Simulation.IMAGE;
}
/**
?*?Get?the?image?of?the?catfish
?*?
?*?@return?filename?of?Catfish?image
?*/
public?String?getImage()?{
if?(getDirection()?==?RIGHT)?{
return?“/Catfish-right.gif“;
}
if?(getDirection()?==?LEFT)?{
return?“/Catfish-left.gif“;
}
if?(getDirection()?==?UP)?{
return?“/Catfish-up.gif“;
}
if?(getDirection()?==?DOWN)?{
return?“/Catfish-down.gif“;
}
return?“Catfish-right.gif“;
}
/**
?*?Look?for?food?in?the?neighborhood.?Consume?some?energy?in?the?process.
?*?
?*?@return?a?neighboring?living?being?that?is?food.
?*/
private?LivingBeing?lookForFoodInNeighborhood()?{
int?neighborIndex;
//?Looking?for?food?consumes?energy.
setEnergy(getEnergy()?-?ENERGY_TO_LOOK_FOR_FOOD);
if?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4340??2005-12-15?19:07??Unit3\EX8\Catfish.java
?????文件???????4333??2005-12-15?19:06??Unit3\EX8\Crocodile.java
?????文件?????????36??2007-07-04?22:01??Unit3\MC_Answer.txt
?????文件????????925??2005-12-15?19:46??Unit3\PQ8\ContractEmployee.java
?????文件????????595??2005-12-15?16:36??Unit3\PQ8\Employee.java
?????文件???????2654??2005-12-15?18:58??Unit3\PQ8\Payroll.java
?????文件????????389??2005-12-15?16:48??Unit3\PQ8\RegularEmployee.java
?????目錄??????????0??2007-06-05?13:09??Unit3\EX8
?????目錄??????????0??2007-06-05?13:09??Unit3\PQ8
?????目錄??????????0??2007-06-05?13:09??Unit3
-----------?---------??----------?-----??----
????????????????13272????????????????????10
評論
共有 條評論