Project: Planting Schedules (Java)

Sustainable Planting and Farming

Home gardens are experiencing a renaissance of sorts as people become aware of the benefits associated with local planting and farming. Planting trees, for example, helps to reduce air pollution and soil erosion, while growing food in a home garden limits exposure to pesticides and reduces the need for non-sustainable farming methods.

planting planting2

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 bettwer quality of life and to reduce stress among citizens. Consider the following video, which discusses a sustainable farming initiative in Sand Diego, CA:

As an alternative situation, the following video describes the use of vacant/abandoned urban land in Detroit as sustainable farming area:

One problem that occurs when you decide to begin a home garden is when and how often to plant the variety of plants, fruits, and vegetables on your list. Suppose you wanted to plant a large garden, with many different vegetables and fruits. Often, multiple “plantings” of the same seeds occur to allow for a consistent schedule of available food. How would know how best to stagger your plantings? It turns out, it involves some simple math.

Java Project: Planting Schedules

This project will provide you with an introduction to the fundamentals of user-defined classes and 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 Java collection(s).
  • Declare, define, and utilize custom Java classes.
  • Write code that utilizes the Java Calendar and GregorianCalendar classes.

As always, be sure to properly document your code. Consult the Java Coding Guidelines document for proper coding standards. Use good design principles and design the solution before attempting to write code.

Create a Java class (program) called Planting.java to produce a planting schedule for a given fruit or vegetable. Your program should have the following inputs:

  • The name of the plant variety (a String);
  • The start planting date (a Calendar);
  • The number of days until maturity (an int > 0);
  • The number of days between plantings, i.e. the interval (an int > 0);
  • The fall frost date (a Calendar).

Your program should receive these inputs and produce a planting schedule. Please note the final planting 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.

As part of your program, you must create a Java class called EdiblePlant to store the user input. This class should implement the following UML specification:

You should fill an object of this class with the data you input, as you input it. Construct your program with five distinct input methods (one for each input) and another method which calls them all, in turn, and returns an EdiblePlant object back to the main() method. Here is an example of what the method might look like:

public EdiblePlant inputPlantInformation()
{
   // Create an object to store the plant information...
   EdiblePlant plant = new EdiblePlant();     

   /* add code here to call the other input methods, and store the return values
      into the "plant" object using the "set" methods */

   // Return the plant information back to the calling method...
   return plant;
}

 

Your program must also use an ArrayList object to contain the planting schedule information (i.e. Calendar objects). This collection must be used to produce the user output (a post-processing step – in other words, completely fill the collection with the planting dates, and then produce the screen report using the collection).

Your program should make use of multiple methods besides main() (use the input/process/output cycle as your guide). The following test cases are provided for you to verify the accuracy of your results. You are encouraged to come up with your own test cases as well to help add to your confidence in your program code:

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): -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

Press any key to continue...

Test Case #2

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

Press any key to continue...

Test Case #3 

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 Melons
=================================
Planting #1: 05/01/2015
Planting #2: 06/12/2015
Planting #3: 07/24/2015

Press any key to continue...

Deliverables

See the instructor for submission instructions and due date(s).

Powered by WordPress. Designed by WooThemes

Skip to toolbar