In: Computer Science
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; } }
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;
}
}