Compile hive
The code is your task.
① Compile hive
Framework Code of the class
Just like writing flower
Similar to the class, you should first
Hive
Class to write a skeleton code. The class diagram is shown in the right figure. Set
Honey
Set to read-only automatic attribute,
Locations
If it is private,
Beecount
It is only used internally, so it can also be a private field.
② Define hive
Constant
Initial number of bees (6
) Requires a constant, the amount of honey at the beginning (
3.2
), The maximum number of honey that can be carried by the honeycomb (
15
), Pollen-to-Honey conversion rate (
0.25
), The maximum number of bees (
8
), The minimum number of honey that can give birth to young bees (
4
).
You need to give these constants A good name and a suitable type. For types, do not just focus on their initial values, but also pay attention to the values of these constants. Double
Best and
Double
Used together,
Int
Best and
Int
.
③ Write code to operate the location
First, write getlocation
() Method. It must accept
String
, In
Locations
Find and return the relevant location in the dictionary. If it cannot be found,
Argumentexception
.
Then, write initializelocation
() Method. This method sets the following locations in the beehive:
◆ Portal (600
,
100
)
◆ Place of conservation (95
,
174
)
◆ Honey Factory (157
,
98
)
◆ Exit (194
,
213
)
Each of these maps to the 2D occupied by the honeycomb.
A point in the space. Later, make sure that the simulator overwrites all these points. In this simulator, we assume that there is only one honeycomb, and the points are fixed. If you want to create multiple honeycomb, you may want to set the point to the coordinates relative to the honeycomb instead of the whole world.
④ Create hive
Constructor
When a beehive is initialized, the honey volume is set to the initial value. You need to set all locations in the beehive and create a random
. Then, call
Addbee
() Method
--
Each time a young bee is created, the newly created
Random
Instance.
Addbee () requires
Random
Object because it adds a random vertex to the nursery
--
In this way, young bees will not overlap.