Write a program that models a snail ranch, as follows.
+REPRODUCTION_RATE : int = 100 {readOnly}
+BASE_POPULATION : int = 200 {readOnly}
-population : int
+SnailRanch(population : int)
+getPopulation() : int
+breed() : void
+harvest() : int
getPopulation() returns the current population, breed() causes the snails to breed
harvest() harvests the snails, returning the yield, the number of snails that could be harvested,
reducing the population to no lower than BASE POPULATION
REPRODUCTION RATE is the number of children per pair of snails
BASE POPULATION is the number of snails to be left in the ranch after a harvest, population is the current population of the ranch
SnailRanch(int) is a constructor that establishes a ranch with an initial population
Implement a Main class that reads a file of events and prints the events, the current
population after each event, and after all events have occurred, prints the total yield from the ranch.The name of the file of events will be supplied as a command line argument.
if the file txt contains these events:
stock 100
breed
breed
harvest
breed
harvest
then a run of the program would look like this:
$ java Main log.txt
stock 100
breed 5100
breed 260100
harvest 200
breed 10200
harvest 200
total yield = 269900
$
The first event will always be "stock" with the initial population of the ranch.
The answer to the question is available in the PDF file https://assignmentexpert.com/https://assignmentexpert.com/homework-answers/programming-answer-54414.pdf
Learn more about our help with Assignments: JavaJSPJSF
Comments
Assignment Expert
03.09.15, 18:04
Dear josh, your record was added.
josh
02.09.15, 10:22
getPopulation() returns the current population, breed() causes the
snails to breed harvest() harvests the snails, returning the yield,
the number of snails that could be harvested, reducing the population
to no lower than BASE POPULATION
josh
02.09.15, 09:44
REPRODUCTION RATE is the number of children per pair of snails BASE
POPULATION is the number of snails to be left in the ranch after a
harvest, population is the current population of the ranch
SnailRanch(int) is a constructor that establishes a ranch with an
initial population
Leave a comment
Thank you! Your comments have been successfully added. However, they need to be checked by the moderator before being published.
Comments
Dear josh, your record was added.
getPopulation() returns the current population, breed() causes the snails to breed harvest() harvests the snails, returning the yield, the number of snails that could be harvested, reducing the population to no lower than BASE POPULATION
REPRODUCTION RATE is the number of children per pair of snails BASE POPULATION is the number of snails to be left in the ranch after a harvest, population is the current population of the ranch SnailRanch(int) is a constructor that establishes a ranch with an initial population
Leave a comment