Josh is conducting an event at every weekend. He will distribute the cold drink and snacks to participants. At end of each event, he will check the event’s outcome as integer i.e., 0=bad, 1=good, or 2=great.
• An event is Good (1) if both cold drink and snacks are at least 10 distributed to participants.
• If either cold drink or snacks is at least double the amount of another one, the event is Great (2).
• If either cold drink or snacks is less than 10 the event is always Bad (0).
Write java program to display an event result as either Great, Good or Bad.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int drink, snacks;
System.out.println("Enter number of cold drinks: ");
Scanner in =new Scanner(System.in);
drink=in.nextInt();
System.out.println("Enter number of snacks: ");
snacks=in.nextInt();
int outcome;
if (drink>=10 && snacks>=10){
outcome=1;
System.out.println("The result of the event is good");
}
else if (drink>=(2*snacks) || snacks>=(2*drink)){
outcome=2;
System.out.println("The result of the event is great");
}
else if (drink<10 || snacks<10){
outcome=0;
System.out.println("The result of the event is bad");
}
}
}
Comments
Leave a comment