Question

Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem....

Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unknown" (followed by a newline) if the value of userItem does not match any of the defined options. For example, if userItem is GR_APPLES, output should be:

Fruit
FOR JAVA
import java.util.Scanner;

public class GrocerySorter {
   public enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
      public static void main (String [] args) {

      GroceryItem userItem = GroceryItem.GR_APPLES;

      /* Your solution goes here  */

      return;
   }
}
PLEASE PUT SOLUTION JUST WHERE IT STATES "YOUR SOLUTION GOES HERE".
1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #2

package grocerysorter;

// Main class

public class GrocerySorter {

    public enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};

    public static void main (String [] args) {

        GroceryItem userItem = GroceryItem.GR_APPLES;

        // Check the useritem is fdruit or apple

        if(userItem == GroceryItem.GR_APPLES || userItem == GroceryItem.GR_BANANAS)

        // If it is fruit print as fruit

        System.out.println("Fruit");

        // If it is drink

        else if(userItem == GroceryItem.GR_JUICE || userItem == GroceryItem.GR_WATER)

        // Print as drink

        System.out.println("Drink");

        else

        // Otherwise print unknown

        System.out.println("Unknown");

        return;

    }

}


answered by: codegates
Add a comment
Answer #1

import java.util.Scanner;

public class GrocerySorter {
public enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
public static void main (String [] args) {

GroceryItem userItem = GroceryItem.GR_APPLES;

/* Your solution goes here */
if(userItem == GroceryItem.GR_APPLES || userItem == GroceryItem.GR_BANANAS) System.out.println("Fruit");
else if(userItem == GroceryItem.GR_JUICE || userItem == GroceryItem.GR_WATER) System.out.println("Drink");
else System.out.println("Unknown");

return;
}
}

Add a comment
Know the answer?
Add Answer to:
Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem....
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
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