A certain granary comprises of two grain silos. Only the first silo has
a loading platform. Grain can be moved from one silo to another.
Create class Granary to implement the functionality of the granary
described above.
(The constructor and accessors interpret negative parameter values as
zero)
- public Granary(double firstSilo, double secondSilo) creates a granary
with silo capacities given as parameters. The silos are empty at the
beginning.
- public double firstCap() returns the amount of grain in the first silo
- public double secondCap() returns the amount of grain in the second silo
- public boolean moveGrain(double amount, boolean fromFirst) moves the
amount of grain declared in the double parameter from one silo to another.
If the boolean parameter is true, the grain is moved from the first silo
to the second, otherwise from second to first. If the whole amount
doesn't fit the target silo, then nothing is moved. Returns true if
the grain was moved, otherwise returns false.
- public boolean addGrain(double amount) adds grain to the first silo.
If the whole amount doesn't fit the silo, then nothing will be added. If
the addition succeeded, true is returned, otherwise false.
- public double takeGrain(double amount) takes grain from the first
silo. If the silo doesn't contain enough grain, then takes all available
grain. Returns the amount of grain taken.
- public void rodentUprising(double severity) decrements the contents
of both silos by the parameter percentage.
- public String toString() returns a clear String representing
the granary's state.
Don't implement the silos as TinyStore-objects!
(14 points)