Question

In: Other

Coding Java Vending machine Lab


Given two integers as user inputs that represent the number of drinks to buy and the number of bottles to restock, create a VendingMachine object that performs the following operations:

  • Purchases input number of drinks

  • Restocks input number of bottles

  • Reports inventory

The VendingMachine is found in VendingMachine.java. A VendingMachine's initial inventory is 20 drinks.

Ex: If the input is:

5 2

the output is:

Inventory: 17 bottles






import java.util.Scanner;

public class LabProgram {
   public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);
      
      /* Type your code here. */ 
      
   }
}


Solutions

Expert Solution

import java.util.Scanner;


public class LabProgram {

        

        public static void main(String[] args) {

                

                Scanner reader = new Scanner(System.in);

                

                int initial = 20;

                int noOfDrinks = reader.nextInt();

                int restocs = reader.nextInt();

                

                int remaining = initial - noOfDrinks + restocs;

                

                System.out.println("Inventory: " + remaining + " bottles");

                

                reader.close();

                

        }

        

}



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,...
Write a java console application,. It simulates the vending machine and ask two questions. When you...
Write a java console application,. It simulates the vending machine and ask two questions. When you run your code, it will do following: Computer output: What item you want? User input: Soda If user input is Soda Computer output: How many cans do you want? User input:            3 Computer output: Please pay $3.00. END The vending machine has 3 items for sale: Soda the price is $1.50/can. Computer should ask “How many cans do you want?” Chips, the price is $1.20/bag....
Sam is considering purchase of a vending machine to sell sodas. The cost of the vending...
Sam is considering purchase of a vending machine to sell sodas. The cost of the vending machine is $3,400. Sam estimates that the vending machine will last for five years and will provide net income of $800 each year for its lifetime. a. If Sam pays $3,400 for the vending machine today, what is its net present value at 7%? Should Sam purchase the vending machine? b. If Sam pays $3,400 for the vending machine today, what is its net...
Simon Teguh is considering investing in a vending machine operation involving 20 vending machines located in...
Simon Teguh is considering investing in a vending machine operation involving 20 vending machines located in various plants around the city. The machine manufacturer reports that similar vending machine routes have produced a sales volume ranging from 600 to 800 units per machine per month. The following information is made available to Teguh in evaluating the possible profitability of the operation. An investment of $45,000 will be required, $9,000 for merchandise and $36,000 for the 20 machines. The machines have...
The objective of this lab is to practice your Verilog coding and the design of a...
The objective of this lab is to practice your Verilog coding and the design of a Finite State Machine. Lab Goal: For this lab, you will code a Verilog module to implement the FSM described in this document. This lab will also require that you use the Seven - Segment Display on the DE0 - CV FPGA board. Design Specifications for the FSM Implem ent the following simple state machine on the DE0 - CV FPGA board. This FSM will...
A soft drink vending machine dispenses cans of drinks at the JKUAT cafeteria. The machine waits...
A soft drink vending machine dispenses cans of drinks at the JKUAT cafeteria. The machine waits for students and/or staff to insert coins. All soft drinks cost KShs. 50 and the machine can only accept Ten, Twenty and Forty shilling coins. A customer must insert a total of fifty shillings for the machine to dispense drinks. (i.)      Give the formal definition of the above machine, as a Finite Automaton. (ii.)     Is the machine deterministic or non-deterministic? Justify your answer (iii.)    Draw a state...
1-You want to dispense an item from the vending machine. An item in the machine can...
1-You want to dispense an item from the vending machine. An item in the machine can cost between 25 cents and a dollar, in 5 cent increments (25,30,35,,40,45......,90,95,100) and the machine accepts only a single dollar bill to pay for the item. Write a java class called ChangeMaker that will determine the change to be dispensed from a vending machine. Use the following UML diagram. ChangeMaker        Attributes    private double money    private int numberOfQuarters    private int...
Using a vending machine requires instructions from the person buying an item and the machine dispensing...
Using a vending machine requires instructions from the person buying an item and the machine dispensing the item. Using terms and concepts learned this week, discuss the following activities. What actions by either the person buying an item or the vending machine would you describe as a privilege or non-privileged instructions? Why? Relate memory management concepts (virtual, real) to the operation of the vending machine. Relate processes and threads to the operation of the vending machine. Directly address each question...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
Written in JAVA Coding Write a java project that reads a sequence of up to 25...
Written in JAVA Coding Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals (sample input data is attached). Store the data in an object designed to store a first name (string), last name (string), and postal code (integer). Assume each line of input will contain two strings followed by an integer value, each separated by a tab character. Then, after the input has been read in, print the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT