The United Nations (UN) has set forth 17 goals for sustainable development. Goal 11 is designed to “Make cities inclusive, safe, resilient and sustainable.” Cities are often overpopulated, which puts strain on the resources and quality of life available in that location. Increased population leads to a need for more services (e.g. transportation, energy consumption) which can cause increased amounts of pollution and limitations on the available financial resources for many municipal projects.
In this project, we will continue exploring one aspect of sustainable development: the creation of sustainable, public gardens in urban areas. This will be the second in a series of projects which revolve around this concept.
Sustainable Greenspace
Urban areas have been promoting the idea of creating gardens and green space areas on tops of buildings, in parks, and in common areas as a way to promote better quality of life and to reduce stress among citizens. Consider the following video, which discusses a rooftop garden in New York City and its benefits:
Rooftop greenspace includes not only urban farms, but also green areas designed to produce more oxygen, provide energy and storm water efficiency, and to provide a welcome break from the metal/concrete scenery found in urban areas. Given that more than half of the world’s populations reside in cities, efforts to produce more sustainable, accessible, and inclusive green areas can greatly impact quality of life issues (e.g. air quality). The city of Philadelphia, for example, is building a series of rooftop gardens – so called “green roofs” – as part of its overall stormwater management plan. These green spaces can also function as public park areas.
Where Can I Learn More?
Here are some links to additional information on this topic:
- Green Roof Benefits, a discussion from the National Park Service
- Shaped By Nature: Reading Hospital Green Roof, a discussion of a nearby rooftop project
- Invert the Green Roof Movement, an interesting discussion of the future of greenspaces
In this project, we will extend the Planting
program to produce a planting schedule for a user-defined crop. This type of computation can be useful for planners looking to maximize the yield of a farming area, whether it be an urban farm, rooftop garden, or traditional farm. In doing so, we will get more experience with Java methods and with one-dimensional arrays.
Java Project: Planting Schedules (Arrays)
This project will provide you with an introduction to the fundamentals of one-dimensional arrays in Java. In this project, you will…
- Develop code to read data from the standard input and produce data to the standard output.
- Write code that conforms to a programming style specified by the instructor.
- Select and implement the appropriate control structure(s) for this problem.
- Decompose the given problem into a sequence of single-purpose methods that are highly cohesive and loosely coupled.
- Declare, define, and initialize one-dimensional arrays of a fixed size.
- Demonstrate the ability to read from and write to an arbitrary array element using array indices.
- Demonstrate an ability to process the entire array, one element at a time, performing both read and write operations.
As you write your code, be sure to properly document your code. Consult the Java Coding Guidelines document (provided by the instructor) for style expectations. Well-written code is easier to debug, easier to maintain over time, and easier to extend as new requirements arise.
Exercise #1: Open the project you completed last time (called Planting
) in your Java development environment. With this exercise, we will begin adding code to produce the planting schedule based on the user input. Your existing program inputs data from the user and echo-prints that output to the screen, using a series of user-defined methods. We want to continue creating methods and integrating them into our larger program.
In your main()
method, create a 128 element, one-dimensional array of type Calendar
. Next, create two methods in your file which outputs the report header (outputReportHeader
) and outputs the contents of the array to the screen (outputDates
). Hint: use a loop, and use what Calendar
gives you. The method headers are shown here:
public static void outputReportHeader(String plant_name) // Outputs the report header to the screen. public static void outputDates( Calendar list[], int size ) // Outputs the dates in the "list" array to the screen in MM/DD/YYYY // format. The "size" parameter is the number of array elements to output. |
Once the methods are created, test them out by adding code to your main
method to call these new methods. Use 128 as the argument for the “size” parameter in outputDates
. Here is a sample test you can run to check if your program is working correctly; please note that some output lines in the report are not shown here for brevity. Make sure your report format matches the example below:
Test Case #1
Please input the plant variety: Green Beans Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): 55 Please enter the number of days between plantings (an integer > 0): 10 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Green Beans Start Date? 05/01/2015 Days Until Maturity? 55 Days Between Plantings? 10 Fall Frost Date? 10/1/2015 Planting Schedule for Green Beans =========================================== Planting #1: 01/01/1900 Planting #2: 01/01/1900 Planting #3: 01/01/1900 Planting #4: 01/01/1900 Planting #5: 01/01/1900 Planting #6: 01/01/1900 Planting #7: 01/01/1900 Planting #8: 01/01/1900 Planting #9: 01/01/1900 ... Planting #127: 01/01/1900 Planting #128: 01/01/1900 |
Exercise #2: Now we will add code to fill the array with a valid planting schedule. Create a method called makePlantingSchedule
which returns an int
and takes as input parameters the user input values, the maximum number of planting dates, and the array to hold the planting dates (i.e pass the array you created in Exercise #1 for the argument). This method will fill the array of planting dates by using a while
loop, starting with the input start date and using the other input values to determine the next planting date. Please note the final planting date and its maturity date should not run into the fall frost date; give yourself at least two weeks between the final maturity date and the fall frost date. The return value should be the number of planting dates produced by the method (less than or equal to 128).
When you have completed the method you must add code to call the method once the user input is complete. Make sure you call the method after the echo-print of the user input, but before you call outputReportHeader
and outputDates
. Remember to modify your call to outputDates
to only output the number of dates for the planting schedule (not 128).
Here are a few sample tests you can run to check if your program is working correctly:
Please input the plant variety: Green Beans Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): -1 *** ERROR! The input value must be an integer > 0. Please try again. Please enter the number of days until maturity (an integer > 0): 55 Please enter the number of days between plantings (an integer > 0): -1 *** ERROR! The input value must be an integer > 0. Please try again. Please enter the number of days between plantings (an integer > 0): 10 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Green Beans Start Date? 05/01/2015 Days Until Maturity? 55 Days Between Plantings? 10 Fall Frost Date? 10/1/2015 Planting Schedule for Green Beans =========================================== Planting #1: 05/01/2015 Planting #2: 05/11/2015 Planting #3: 05/21/2015 Planting #4: 05/31/2015 Planting #5: 06/10/2015 Planting #6: 06/20/2015 Planting #7: 06/30/2015 Planting #8: 07/10/2015 Planting #9: 07/20/2015 |
Test Case #3
Please input the plant variety: Melons Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): 70 Please enter the number of days between plantings (an integer > 0): 21 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Melons Start Date? 05/01/2015 Days Until Maturity? 70 Days Between Plantings? 21 Fall Frost Date? 10/1/2015 Planting Schedule for Melons =========================================== Planting #1: 05/01/2015 Planting #2: 05/22/2015 Planting #3: 06/12/2015 Planting #4: 07/03/2015 |
Test Case #4
Please input the plant variety: Squash Please enter the start date as month day year: 05 1 2015 Please enter the number of days until maturity (an integer > 0): 48 Please enter the number of days between plantings (an integer > 0): 42 Please enter the fall frost date as month day year: 10 1 2015 You entered: Plant Variety? Squash Start Date? 05/01/2015 Days Until Maturity? 48 Days Between Plantings? 42 Fall Frost Date? 10/1/2015 Planting Schedule for Squash =========================================== Planting #1: 05/01/2015 Planting #2: 06/12/2015 Planting #3: 07/24/2015 |
Your program is now complete.
Deliverables
See the instructor for submission instructions and due date(s).