Question

In: Computer Science

A vending machine serves chips, fruit, nuts, juice, water, and coffee. The machine owner wants a...

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. */
}
}

Solutions

Expert Solution

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:


Related Solutions

In Java): A vending machine serves chips, fruit, nuts, juice, water, and coffee. The machine owner...
In Java): 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,...
A vending machine dispenses coffee. The average cup of coffee is supposed to contain 7.0 ounces....
A vending machine dispenses coffee. The average cup of coffee is supposed to contain 7.0 ounces. Eight cups of coffee from this machine show the average content to be 7.3 ounces with a standard deviation of 0.5 ounce. Using a 5% level of significance, test whether the machine has slipped out of adjustment and if the average amount of coffee per cup is different from 7 ounces. Determine the p-value and interpret the results
The amount of coffee dispensed by a drink vending machine is normally distributed with a mean...
The amount of coffee dispensed by a drink vending machine is normally distributed with a mean of 12.1 oz. What is the probability that a randomly selected cup of coffee has more than 12.8 oz? Assume that the standard deviation for all drink vending machines is 0.38
A manufacturer of coffee vending machines has designed a new, less expensive machine. The current machine...
A manufacturer of coffee vending machines has designed a new, less expensive machine. The current machine is known to dispense an average of 5 fl. oz., with a standard deviation of .2 fl. oz., into cups. When the new machine is tested using 15 cups, the mean and the standard deviation of the fills are found to be 5 fl. oz. and .213 fl. oz. Test H0: σ = .2 versus Ha: σ ≠ .2 at levels of significance .05...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at her shop. She selects a random sample of 60 customers during a certain week. Data are available in the worksheet labeled “Problem 2” in the spreadsheet. 1. Construct a 90% confidence interval on the proportion of customers who say they “definitely will” recommend the specialty coffee shop to family and friends. Problem 2 Data Set Note: Y is an indicator variable, i.e., if Y=1,...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at her shop. She selects a random sample of 60 customers during a certain week. Data are available in the worksheet labeled “Problem 2” in the spreadsheet Final_SU2020_Data_Sets.xlsx. 1. At the ? = 0.1 level of significance, is there evidence that more than 50% of the customers say they “definitely will” recommend the specialty coffee shop to family and friends? 2. Construct a 90% confidence...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at her shop. She selects a random sample of 60 customers during a certain week. Data are available in the worksheet labeled “Problem 2”. 1. At the a = 0.1 level of significance, is there evidence that more than 50% of the customers say they “definitely will” recommend the specialty coffee shop to family and friends? 2. Construct a 90% confidence interval on the proportion...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at...
The owner of a specialty coffee shop wants to study coffee purchasing habits of customers at her shop. She selects a random sample of 60 customers during a certain week, with the following results: • The amount spent was X = +7.25, S = +1.75. • Thirty-one customers say they “definitely will” recommend the specialty coffee shop to family and friends. a. At the 0.05 level of significance, is there evidence that the population mean amount spent was different from...
John wants to estimate the market potential for a low-carbohydrate fruit juice in the U.S. His...
John wants to estimate the market potential for a low-carbohydrate fruit juice in the U.S. His research shows that 50% of the population of the U.S. drinks fruit juice; 10% of all fruit juice drinkers are interested in low-carb juice; the amount of fruit juice consumed per month by those who drink juice is 2 gallons; and the average price per gallon is $5. Assuming that the total population of the U.S. is 300 million, the market potential for low-carb...
The owner of a restaurant that serves continental food wants to study characteristics of his customers....
The owner of a restaurant that serves continental food wants to study characteristics of his customers. He decides to focus on two variables: the amount of money spent by customers and whether customers order dessert. The results from a sample of 60 customers are as follows: • Amount spent ( =$38.54, S= $7.26) • 18 customers purchased dessert. Construct a 95% confidence interval estimate of the population mean amount spent per customer in the restaurant.      _____________ Construct a 90% confidence...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT