In: Computer Science
A vending machine serves chips, fruit, nuts, juice, water, and coffee. The machine owner wants a daily report indicating what items sold that day. Given boolean values (true or false) indicating whether or not at least one of each item was sold (in the order chips, fruit, nuts, juice, water, and coffee), output a list for the owner. If all three snacks were sold, output "All-snacks" instead of individual snacks. Likewise, output "All-drinks" if appropriate. For coding simplicity, output a space after every item, including the last item.
Ex: If the input is false false true true true false, output:
Nuts Juice Water
Ex: If the input is true true true false false true, output:
All-snacks Coffee
Ex: If the input is true true true true true true, output:
All-snacks All-drinks
Ex: If the input is false false false false false false, output:
No items
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
boolean chipsSold; // Snack items
boolean fruitSold;
boolean nutsSold;
boolean juiceSold; // Drink items
boolean waterSold;
boolean coffeeSold;
chipsSold = scnr.nextBoolean();
fruitSold = scnr.nextBoolean();
nutsSold = scnr.nextBoolean();
juiceSold = scnr.nextBoolean();
waterSold = scnr.nextBoolean();
coffeeSold = scnr.nextBoolean();
/* Type your code here. */
}
}
CODE IN JAVA:
VendingMachine.java file:
import java.util.Scanner;
public class VendingMachine {
public static void main(String[] args) {
// TODO Auto-generated method
stub
Scanner sc = new
Scanner(System.in);
boolean chipsSold; // Snack
items
boolean fruitSold;
boolean nutsSold;
boolean juiceSold; // Drink
items
boolean waterSold;
boolean coffeeSold;
System.out.print("Enter the
statistics of vending machine:");
chipsSold = sc.nextBoolean();
fruitSold = sc.nextBoolean();
nutsSold = sc.nextBoolean();
juiceSold = sc.nextBoolean();
waterSold = sc.nextBoolean();
coffeeSold =
sc.nextBoolean();
if(chipsSold==true &&
fruitSold==true && nutsSold == true)
System.out.print("All-snacks ");
else {
if(chipsSold)
System.out.print("Chips ");
if(fruitSold)
System.out.print("Fruits ");
if(nutsSold)
System.out.print("Nuts ");
}
if(juiceSold==true &&
waterSold==true && coffeeSold == true)
System.out.print("All-drinks ");
else {
if(juiceSold)
System.out.print("Juice ");
if(waterSold)
System.out.print("Water ");
if(coffeeSold)
System.out.print("Coffee ");
}
if(chipsSold==false &&
fruitSold==false && nutsSold == false &&
juiceSold==false && waterSold==false && coffeeSold
== false) {
System.out.print("No items");
}
System.out.println("");
}
}
OUTPUT: