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...
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 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....
Write a Python program that prompts the user to enter their three favorite bands separate by commas, and prints their selections on three separate bands. Hint: You will need to use the string function, split. A sample run appears below (user input shown in bold): Enter your favorite bands separated by commas: The Beatles,Queen,Bruce Springsteen My favorite bands are: The Beatles Queen Bruce Springsteen
Using Swift, Write a program that reads in a string and passes to a function named parse(digit:) that takes a string with one character as parameter. The function should return -1 if the input is not a digit character and the digit otherwise. You must use a switch statement parse(digit: "1") // 1 parse(digit: "3") // 3 parse(digit: "a") // -1
Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...