Question

In: Computer Science

Print either "Fruit", "Drink", or "Unknown" (followed by anewline) 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;
   }
}

Solutions

Expert Solution

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;

    }

}



Related Solutions

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 #include <stdio.h> int main(void) { enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER}; enum GroceryItem userItem = GR_APPLES; /* Your solution goes here */ return 0; } USE C PLEASE
Print either "Fruit", "Drink", or "Unknown" (followed by anewline) 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 = GR_APPLES, output should be: Fruit Sample program: #include using namespace std; int main() { enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER}; GroceryItem userItem = GR_APPLES; return 0; } Below, do not type an entire program. Only type the portion indicated by...
Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by...
Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a space. Ex: If origList = {4, 5, 10, 12} and offsetAmount = {2, 4, 7, 3}, print: 6 9 17 15 import java.util.Scanner; public class VectorElementOperations { public static void main (String [] args) { final int NUM_VALS = 4; int[] origList = new int[NUM_VALS]; int[] offsetAmount = new int[NUM_VALS]; int i; origList[0] = 20; origList[1] = 30; origList[2] = 40; origList[3] =...
Real Fruit Juice: A 32 ounce can of a popular fruit drink claims to contain 20%...
Real Fruit Juice: A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 44 such cans of this fruit drink. Of these, the mean volume of fruit juice is 6.33 with standard deviation of 0.19. Test the claim that the mean amount of real fruit juice in all...
Real Fruit Juice: A 32 ounce can of a popular fruit drink claims to contain 20%...
Real Fruit Juice: A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 56 such cans of this fruit drink. Of these, the mean volume of fruit juice is 6.36 with standard deviation of 0.21. Test the claim that the mean amount of real fruit juice in all...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 30 such cans of this fruit drink. The amount of real fruit juice in each can is given in the table below. Test the claim that the mean amount of real...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 30 such cans of this fruit drink. The amount of real fruit juice in each can is given in the table below. Test the claim that the mean amount of real...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 30 such cans of this fruit drink. The amount of real fruit juice in each can is given in the table below. Test the claim that the mean amount of real...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 30 such cans of this fruit drink. The amount of real fruit juice in each can is given in the table below. Test the claim that the mean amount of real...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink...
Real Fruit Juice (Raw Data, Software Required): A 32 ounce can of a popular fruit drink claims to contain 20% real fruit juice. Since this is a 32 ounce can, they are actually claiming that the can contains 6.4 ounces of real fruit juice. The consumer protection agency samples 30 such cans of this fruit drink. The amount of real fruit juice in each can is given in the table below. Test the claim that the mean amount of real...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT