Write a program that performs a survey tally on beverages. The program should pr
ID: 3685954 • Letter: W
Question
Write a program that performs a survey tally on beverages. The program should prompt for the next person until a sentinel value of -1 is entered to terminate the program. Each person participating in the survey should choose their favorite beverage from the following list: 1. Coffee 2. Tea 3. Coke 4. Orange Juice Sample Run: Please input the favorite beverage of person #1: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the prgram 4 Please input the favorite beverage of person #2: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the prgram 1 Please input the favorite beverage of person #3: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the prgram 3 Please input the favorite beverage of person #4: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the prgram 1 Please input the favorite beverage of person #5: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the prgram 1 Please input the favorite beverage of person #6: Choose 1, 2, 3, or 4 from the above menu or -1 to exit the prgram -1 The total number of people surveyed is 5. The results are as follows: Beverage Option 2: Suppose Dava drops a watermelon off a high bridge and lets it fall until it hits the water. If we neglect air resistance, then the distance d in meters fallen by the watermelon after t seconds is d = 0.5 'g' mt^2, where the acceleration of gravity g = 9.8 meters/second^2. Write a program that asks the user to input the number of seconds that the watermelon falls and the height h of the bridge above the water. The program should then calculate the distance fallen for each second fron t = 0 unitl the value of t input by the user. If the total distance fallen is greater then the height of the bridge, then the program should tell the user that the distance fallen is not valid.Explanation / Answer
SOlution:
package com.nancy.chegg.qanda;
import java.util.Scanner;
public class BeverageSurvey {
public static void main(String[] args) {
//Declaring variables
int countCoffee = 0;
int countTea = 0;
int countCoke = 0;
int countjuice = 0;
int input;
int countPeople = 1;
//Menu to display
System.out.println("---Menu---");
System.out.println("1. Cofee");
System.out.println("2. Tea");
System.out.println("3. Coke");
System.out.println("4. Orange Juice");
Scanner scan = new Scanner(System.in);
do {
System.out.println("Please input the favorite beverage of person #"
+ countPeople
+ ": Choose 1, 2, 3 or 4 from the above menu or -1 to exit the program.");
input = scan.nextInt();
switch (input) {
case 1 :
countCoffee++;
break;
case 2 :
countTea++;
break;
case 3 :
countCoke++;
break;
case 4 :
countjuice++;
break;
}
countPeople++;
} while (input != -1);
System.out.println("The total number of people surveyed is "
+ (countPeople - 1) + ". The results are as follows: ");
System.out.println(" Beverage Number of Votes");
System.out.println("---------------------------");
System.out.println("Coffee " + countCoffee);
System.out.println("Tea " + countTea);
System.out.println("Coke " + countCoke);
System.out.println("Orange Juice " + countjuice);
scan.close();
}
}
Sample output:
---Menu---
1. Cofee
2. Tea
3. Coke
4. Orange Juice
Please input the favorite beverage of person #1: Choose 1, 2, 3 or 4 from the above menu or -1 to exit the program.
1
Please input the favorite beverage of person #2: Choose 1, 2, 3 or 4 from the above menu or -1 to exit the program.
2
Please input the favorite beverage of person #3: Choose 1, 2, 3 or 4 from the above menu or -1 to exit the program.
3
Please input the favorite beverage of person #4: Choose 1, 2, 3 or 4 from the above menu or -1 to exit the program.
4
Please input the favorite beverage of person #5: Choose 1, 2, 3 or 4 from the above menu or -1 to exit the program.
-1
The total number of people surveyed is 5. The results are as follows:
Beverage Number of Votes
------------------------------------------
Coffee 1
Tea 1
Coke 1
Orange Juice 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.