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.
s = input.nextLine();
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 |
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
=================================
// VegetablePricer.java
import java.util.Scanner;
public class VegetablePricer {
public static void main(String[] args) {
String vegs[] = { "artichoke",
"broccoli", "carrot", "okra", "tomato" };
double price[] = { 2.21, 2.57,
0.74, 3.21, 3.69 };
String inVeg;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
// Getting the input entered by
the user
System.out.print("Enter Vegitable
name :");
inVeg = sc.nextLine();
//based on the user input
displaying the price
switch (inVeg.toLowerCase())
{
case "artichoke": {
System.out.println("Cost per pound is :$" + price[0]);
break;
}
case "broccoli": {
System.out.println("Cost per pound is :$" + price[1]);
break;
}
case "carrot": {
System.out.println("Cost per pound is :$" + price[2]);
break;
}
case "okra": {
System.out.println("Cost per pound is :$" + price[3]);
break;
}
case "tomato": {
System.out.println("Cost per pound is :$" + price[4]);
break;
}
}
}
}
===========================
Output:
Enter Vegitable name :okra
Cost per pound is :$3.21
=====================Could you plz rate me well.Thank You
Write a program named "VegetablePricer" which prompts the user for a vegetable from the pricing table...
Program must be in Python 3.
Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...
Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...
***LOOPS NOT ALLOWED*** String variables and use of String methods: Write a complete Java program which prompts the user for a string with 3 words each separated by a single space and reads the line into one String variable using nextline(). Extract each word and add them to a new String variable in reverse order with a space between the words. Have the 1st letter of the new string in upper case and all other strings in lower case letter....
In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....
Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...
Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...
Write a program that will accept an integer as input from the user and test if that input is an even number. It should also test if the input is evenly divisible by 6. The program should display “Even” if the user’s input is even. It should additionally display “divisible by 6” if the user’s input is evenly divisible by six. #include <iostream> using namespace std; int main(){ return 0; } Convert the following switch statement to an if-...
Question 2 Use a switch statement to write the following program: Using C++ The program prompts the user for a letter grade (of type char). The list of valid letter grades is: A B C D E F The program should consider both lower and upper case The program will then display the following messages: For grade ‘A’: display “Excellent” For grade ‘B’: display “Good” For Grade ‘C’: display “Average” For grade ‘D’ or ‘E’: display “Below Average” For Grade...
Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...
Write a program, which reads a list of student records from a file in batch mode. Each student record comprises a roll number and student name, and the student records are separated by commas. An example data in the file is given below. · SP18-BCS-050 (Ali Hussan Butt), SP19-BCS-154 (Huma Khalid), FA19-BSE-111 (Muhammad Asim Ali), SP20-BSE-090 (Muhammad Wajid), SP17-BCS-014 (Adil Jameel) The program should store students roll numbers and names separately in 2 parallel arrays named names and rolls, i.e....