Question

Assignment 7.2: Fruit Codes (10 pts) 70% of the produce sold in the U.S. contains pesticide...

Assignment 7.2: 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.

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."

Name your file Fruit.java.

The program should work identically to the sample output below.

Additionally, your code should use exactly two sets of if-else statements for full credit (note that the use of else if is not allowed on this assignment).

Sample Output:


Enter the fruit code: 96544

Your fruit was not genetically modified, and was grown according USDA organic standards.


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Summary:-

BufferedReader -

  • It is used to accept the input from user line by line. It is pre-defined classes in package java.io.*.
  • It throws IOException.

Following are the methods used in the code:-

  • length() - returns the length of string.
  • charAt(index) - returns the character at specific index in the string.

Code:-

Note: Code is written in Netbeans IDE. Save it as Fruit.java.

(Please refer the comments in the code as they are self-explanatory)

import java.io.*;
public class Fruit {
  
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  
System.out.print("Enter the fruit code :");
String y=br.readLine();
if(y.length()==4){
System.out.println("Your fruit was grown conventionally, with the use of pesticides and chemicals.");
}else{
  
if(y.length()==5 && y.charAt(0)=='8'){
System.out.println("Your fruit was genetically modified.");
}else{
System.out.println("Your fruit was not genetically modified, and was grown according USDA organic standards.");
}
}
}
}

Indented Code with Snapshots:

Output:-

Add a comment
Know the answer?
Add Answer to:
Assignment 7.2: Fruit Codes (10 pts) 70% of the produce sold in the U.S. contains pesticide...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT