Question: Write a Java program to track the growth of a plant. You are given two arrays that store the average temperature and rainfall in San
Write a Java program to track the growth of a plant.
You are given two arrays that store the average temperature and rainfall in San Francisco, for months 0 to 11, representing January to December respectively.
final int NUMMONTHS = 12;
int [] avgTemp = {46, 48, 49, 50, 51, 53, 54, 55, 56, 55, 51, 47};
int [] avgRain = {5, 3, 3, 1, 1, 0, 0, 0, 0, 1, 3, 4};
You are starting a new plant in month 0. You are given the declaration for an array newGrowth[]; newGrowth[i] will keep track of the number of inches of growth in month i.
int [] newGrowth;
newGrowth = new int[NUMMONTHS];
What your program does:
Prompt the user to enter the minimum and maximum temperature for the plant
Prompt the user to enter the minimum rainfall for the plant
(all temperatures and rainfall are integers, for simplicity)
for each month i from 0 to 11, calculate newGrowth[i]:
if the average temperature for month i is the maximum, newGrowth[i] is set to -1 (plant dies back);
otherwise, newGrowth[i] is set to the average rainfall for month i minus the minimum rainfall for the plant
The plant starts at height = 0 inches. For each month, calculate the height of the plant at the end of the month, and print a table as shown in the sample runs, displaying the month, the average temperature, the average rainfall, the new growth, and the height of the plant at the end of that month. (Align columns of the table using tabs.) Note that the height of the plant never becomes negative; the smallest height attained is always zero.
PART 2 PlantGrowth Database: Add the Month column to your PlantGrowth table. When the program is generating the table, it should be saving the tables data in a 2D array. This array holds items of different types, at least 2 types. You decide how many rows and columns your array should have:
PART 3 Table header and formatting 1. Store the table header as part of the 2D array. The table header is the first row of the report table: Index Month Temp Rain Growth Plant Height Briefly explain your approach in minimum 3 complete sentences. 2 points 2. Display the contents of the Growth column correctly; Show positive or negative sign of each number.
Output:
Your program displays the array before terminating. Its output must be identical to the output of the sample runs below. Print data in the "Growth" column in the correct format for extra credits, PART 4 run: run: | Tie|come to the 210 gardening planner! | Welcome to the 210 gardening planner! Enter minimum temperature for plant: 47 Enter maximum temperature for plant: 60 Enter minimum rainfall for plant: 0 Index Month Temp Enter minimum temperature for plant: 45 Enter maximum temperature for plant: 50 Enter minimum rainfall for plant: 2 Index Month Temp RainGrowth Plant Height Rain Growth Plant Height Jan 46 Jan Feb Mar 46 49 50 Mar 50 51 53 54 May May 53 54 Jul Aug Sep Oct Nov Dec Aug Sep 56 56 12 16 10 51 47 Nov 10 Dec PART 3, displaying the plantGrowthDatabase: PART 3, displaying the plantGrowthDatabase: Index Month Temp Rain Growth Plant Height Index Month Temp Rai Growth Plant Height 46 48 Jan 46 Jan Feb Mar Mar 50 51 53 50 51 53 54 May May Jul Aug Sep Aug 56 Sep 56 10 12 16 Nov Nov 51 Dec Dec 47 BUILD SUCCESSFUL (total time: 6 seconds) BUILD SUCCESSFUL (total time: 4 seconds)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
