In java please, Write a program called Survey that tallies the results for a bev
ID: 3724553 • Letter: I
Question
In java please,
Explanation / Answer
As per your requirement the below one is solution please follow it
Source Code:-
---------------------------
package com.venkanna;
import java.util.Scanner;
public class Servey {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int option=0,Coffee=0,Milk=0,red_bull=0,Water=0;
try{
do
{
System.out.println("1.Coffe 2.Milk 3.Red_Bull 4. Water");
System.out.println("Please Enter the Person's Choice");
option=sc.nextInt();
switch(option)
{
case 1:
Coffee++;
break;
case 2:
Milk++;
break;
case 3:
red_bull++;
break;
case 4:
Water++;
break;
case -1:
break;
default:
System.out.println("Wrong Option");
}
}while(option!=-1);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("Servey Results");
System.out.println("Coffee "+Coffee+" Milk "+Milk+" red_bull "+red_bull+" Water "+Water);
}
}
Sample Output:-
====================
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
1
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
2
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
4
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
1
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
2
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
4
1.Coffe 2.Milk 3.Red_Bull 4. Water
Please Enter the Person's Choice
-1
Servey Results
Coffee 2
Milk 2
red_bull 0
Water 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.