Problem 1: Simulate Seed Growth 2 1 Figure 1: Plants in various stages of growth. The...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Heres the implementation of the GrowthSim program in Java import javautil class Vegetable String nam... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
What type of business is S. G. Cowen? How is this firm different from the other financial firms? How systems and operations of financial firms are different from other types of businesses - say...
-
THIRD AVENUE SOFTWARE HEALTH-CARE APP PROJECT This case is new for the ninth edition of Information Technology Project Management . The case provides an opportunity to apply agile and Scrum...
-
Cliff Arthur has equally attractive job offers in Miami and Los Angeles. The rent ratios in the cities are 8 and 20, respectively. Cliff would really like to buy rather than rent a home after he...
-
Listed below are amounts of strontium-90 (in millibecquerels, or mBq) in a simple random sample of baby teeth obtained from Pennsylvania residents born after 1979 (based on data from "An Unexpected...
-
Assume that commercial banks have $100 billion of checking deposits and $4 billion of vault cash. Further assume tlrnt reserve requirements are 10 percent of checking deposits. Lastly, assume that...
-
The uranium in the earth's crust is \(0.7 \%{ }^{235} \mathrm{U}\) and \(99.3 \%{ }^{238} \mathrm{U}\). Two billion years ago, \({ }^{235} \mathrm{U}\) comprised approximately \(3 \%\) of the uranium...
-
Barry Carter is considering opening a music store. He wants to estimate the number of CDs he must sell to break even. The CDs will be sold for $13.98 each, variable operating costs are $10.48 per CD,...
-
WAP to enter the 5 subjects numbers and p [ rint the grades for each subject?
-
Using examples of masculine characteristics represented in Hollywood genres of action and Vietnam war films, explain why media is a site of cultural and political reproduction of social inequality by...
-
A checklist ensuring that the organisation's policies and procedures ensure that there are measures in place to prevent a breach of contract. This must ensure that organizational policies and...
-
As a health care manager, what strategies will you use to market your health care clinic, facility, product, or service? Provide examples.
-
Would a two-tier health care system (privatization) be a viable solution to improving Canada's universal health care system? Support your for or against argument with examples from other countries...
-
Health care markets in the United States are rapidly changing. The effectiveness of marketing techniques, competition, and the demands for health care services vary by geographic region for a variety...
-
A supervisor's discipline helps ensure that employees follow established processes that are crucial to the quality and cost of warehouse operations. Establishing a rapport with employees that...
-
1.- ArtDeco is a Mexican company dedicated to the sale and manufacture of wooden furniture. Despite its success, there are some problems in its manufacturing process, since the wood used to produce...
-
AB CORPORATION ISSUED THE FOLLOWING 850 COMMON STOCKS PAR VALUE P100 750 PARTICIPATING PREFERRED STOCKS PAR VALUE P100 AT 3% AB CORPORATION DECLARED P100,000.00 DIVIDEND IN 2022.
-
Listed below' are several transactions that occurred during the year. All these amounts in each case were capitalized to an account called R&D costs. At the end of the year the company wants this...
-
On January 20, 2000, the Financial Post published an article by Philip Mathias entitled, "Intrawest points to accounting report for fall in stock price. Intrawest owns and operates Whistler Blackcomb...
-
Variable Value Limited (VAT,) was incorporated on January 1, 2011 when the sole shareholder invested $1,000,000. This is the only financing the firm needed. WL had a single project which it developed...
-
Use five different websites to investigate three companies in your career field. Look at salary guides for your level of qualifications, product/service information, news articles about the...
-
Interview someone working in a field youre interested in. Use the following questions to get started: How did you get started in this field? What do you like about your job? What do you dislike...
-
Using a cover letter you have written, review your online presence. What key words do you see in your social networking profiles? What job experience, education, and skills are highlighted? How can...
Study smarter with the SolutionInn App