Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the Java code for the following: Write a program named \"VegetablePricer\

ID: 3886258 • Letter: I

Question

I need the Java code for the following:

Write a program named "VegetablePricer" which prompts the user for a vegetable from the pricing table shown below. The program will then display the cost per pound for that vegetable, again using the table provided.

Your program must use a switch statement to process the input value and display the desired output.

Be sure to provide a default case in your switch statement which handles unrecognized input.

Use named constants for all constant strings (e.g. prompts and vegetable names) and price values.

Provide an identification header block and descriptive comments throughout.

Use consistent indentation, whitespace for readability, and camelHump format for multi-word variable names. T

o read a String value from the keyboard, assuming a Scanner variable named input and String variable named s, use s = input.nextLine();

When comparing two strings, you should either do a case-insensitive comparison or convert the strings to one consistent case. For instance, if my input variable for this program is "String inVeg", my switch statement to compare against the available choices looks like this: switch (inVeg.toLowerCase()) {

so I can consistently compare against my all lower case vegetable name string constants.

Vegetable Pricing Table Vegetable Name Vegetable Price per Lb.

artichoke $2.21

broccoli $2.57

carrot $0.74

okra $3.21

tomato $3.69

Expected Output (program run multiple times with different input; user input is shown in red):

Please enter a vegetable name. Choices are:

artichoke

broccoli

carrot

okra

tomato

Your choice => artichoke

artichoke: Price per lb. is $2.21

Please enter a vegetable name. Choices are:

artichoke

broccoli

carrot

okra

tomato

Your choice => broccoli

broccoli: Price per lb. is $2.57

Please enter a vegetable name. Choices are:

artichoke

broccoli

carrot

okra

tomato

Your choice => carrot

carrot: Price per lb. is $0.74

Please enter a vegetable name. Choices are:

artichoke

broccoli

carrot

okra

tomato

Your choice => okra

okra: Price per lb. is $3.21

Please enter a vegetable name. Choices are:

artichoke

broccoli

carrot

okra

tomato

Your choice => tomato

tomato: Price per lb. is $3.69

Please enter a vegetable name. Choices are:

artichoke

broccoli

carrot

okra

tomato

Your choice => beans

beans: Sorry, that vegetable is not recognized.

Explanation / Answer

import java.util.*;

import java.util.Scanner;

public class VegetablePricer{

public static void main(String[] args){

Scanner input = new Scanner(System.in);

System.out.println("Please enter a vegetable name. Choices are: ");

System.out.println("artichoke broccoli carrot okra tomato ");

String s = input.nextLine();

System.out.println("Your choice => "+s.toLowerCase());

switch(s.toLowerCase()){

case "artichoke":

System.out.println("artichoke: Price per lb. is $2.21");

break;

case "broccoli":

System.out.println("broccoli: Price per lb. is $2.57");

break;

case "carrot":

System.out.println("carrot: Price per lb. is $0.74");

break;

case "okra":

System.out.println("okra: Price per lb. is $3.21");

break;

case "tomato":

System.out.println("tomato: Price per lb. is $3.69");

break;

default:

System.out.println(s+": Sorry, that vegetable is not recognized.");

break;

}

}

}