Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1: Simulate Seed Growth 2 1 Figure 1: Plants in various stages of growth. The Dalhousie School of Agriculture has been developing new
Problem 1: Simulate Seed Growth 2 1 Figure 1: Plants in various stages of growth. The Dalhousie School of Agriculture has been developing new seeds for common vegeta- bles. Before planting them, they want you to help simulate their expected growth. Write a program called GrowthSim.java that reads in information on vegetables then outputs the expected number of plants after a specific time spent growing. The growth of a plant can be represented by an integer representing the number of days. it has been growing as seen in Figure 1. A plant starts off as a seedling and takes a fixed. number of days to reach maturity. Once a plant reaches maturity it produces new seeds. It then waits for another shorter period before it flowers and produces seeds again. Your program will receive a series of plants in various stages of growth as input. It will then simulate a fixed number of days and determine how many plants are created. Input Your program should read in the input using a Scanner object, which is instantiated with System.in. The input will consist of several lines of text. The first line contains a single integer, N, denoting the number of vegetables to be read in. Every vegetable is represented. by the following 3 lines. 1. A vegetable is represented by a single line and will be of the form: where V GF P V is the name of the vegetable (always a single word). G is the germination time, i.e., the number of days it takes a brand new seed to reach maturity and produce additional seeds. F is the flowering time, i.e. the number of days it takes a mature plant to produce seeds again. P is the number of seeds produced when the plant reaches maturity or flow- ers. 2. After each vegetable you will read in a single integer S that denoting the initial number of plants for that vegetable. 3. The third line consists of S integers separated by spaces. Each integer s = (0, G) and represents a plant at a specific day in its germination cycle The final line is a single integer D that denotes the number of days to run the simulation for. Hint: Use the Scanner object to easily parse the input. For this assignment you only need to use the nextInt() and next() methods. Processing The simulation consists of zero or more days where each day represents one (1) period of growth. (Hint: you will need a main loop, where each iteration of the loop simulates one day.) Day d refers to the growing that takes place in day of the simulation. The simulation ends after D days. On a single day d every plant advances one step closer to maturity. Plants vary in time to reach maturity, specified by G. Once a plant has reached maturity, i.e., spent G days growing, its produces P seeds. Each of these seeds will then start growing as a new plant. The original plant was then wait F days before it produces seeds again. Every plant in the simulation goes through this process. Your simulation must keep track of how many of each variety of plants are growing. Hints: You program should consists of two phases. The first phase reads in the input and creates the data structures, while the second handles the simulation. You can track each variety of plants separately. The growth rate of the seeds is very large, so think about how you can keep track of many plants. Output Your program should output to the console (System.out). The output consists of N lines, one per vegetable from the input. Each line contains the name of vegetable, a space, and the total number of plants of that vegetable (in any germination stage) at the end of the simulation. The order of the words must be the same as the input. Examples Sample Input 1 Potato 3 22 1 0 3 Sample Input 1 Potato 322 3 2 1 2 Sample Output Potato 3 Sample Output Potato 13 3 Sample Input 2 Potato 322 3 0 0 0 Peas 7 4 6 3 0 0 0 3 Sample Output Potato 9 Peas 3
Step by Step Solution
★★★★★
3.54 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
Heres the implementation of the GrowthSim program in Java import javautil class Vegetable String nam...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started