Assignment 8
Due Tuesday, May 12 at 11:59pm on Canvas


Important: You must only use concepts and methods taught in class to complete this assignment - or you will receive a 0 on this assignment



Pair Programming Required (Or You Will Receive a 0)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your assignment code to Canvas.
  • Please make sure both your names are on your file (hint: use a proper Javadoc comment)
  • If you need help finding a partner, please contact me as soon as possible.

Assignment 8: Fruit Codes (10 pts)

  • 70% of the produce sold in the U.S. contains pesticide residues [1].
  • One large study published in the respected medical journal JAMA, found that people who consumed the most organic foods had 25% fewer cancers than those who ate no organic food [2].
  • Additionally, foods that are genetically modified tend to be sprayed with large amounts of weed killers [3].
  • Regardless of these concerns, most nutrition experts agree that eating fruits and vegetables - either conventional or organic - in large quantities is one of the most important things you can do for your health [4]
  • Write a program to read in the code printed the sticker on a piece of fruit and print out whether the fruit was grown organically, or conventionally or was genetically modified.
  • The program should prompt the user to enter the numeric code on the fruit's sticker, and then read in the user's response as a String.
  • Codes that are 4 digits long indicate that the fruit has been grown conventionally.
    • In this case, print the message: "Your fruit was grown conventionally, with the use of pesticides and chemicals."
  • Codes that are 5 digits long, and start with an 8, indicate that the fruit has been genetically modified.
    • In this case, print the message: "Your fruit was genetically modified."
  • Codes that are 5 digits long, and start with a 9, indicate that the fruit was grown organically.
    • In this case, print the message: "Your fruit was not genetically modified, and was grown according USDA organic standards."
  • Codes that do not follow the above format are considered invalid.
  • Name your file Fruit.java.
  • The program should work identically to the sample output below.
  • Additionally, your code should use exactly one if, two else ifs and one else.
  • For full credit, you must use the String methods covered in class in your solution to this assignment. If you use String methods we did not cover in class, you will receive a 0 on this assignment.
Sample Output:

Enter the fruit code: 96544
Your fruit was not genetically modified, and was grown according USDA organic standards.


Sample Output:

Enter the fruit code: 8455
Your fruit was grown conventionally, with the use of pesticides and chemicals.


Sample Output:

Enter the fruit code: 84556
Your fruit was genetically modified.


Sample Output:

Enter the fruit code: 123
Invalid code. Please try again.


Sample Output:

Enter the fruit code: 12345678
Invalid code. Please try again.

  • When your program is working as shown above and meets the specified requirements, submit it to Canvas.