Question

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


3 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

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();

                

        }

        

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Coding Java Vending machine Lab
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT