subject

LAB: Vending machine 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
Current file: LabProgram. java
1 import java. util. Scanner;
2
3 public class LabProgram {
4 public static void main(String[] args) {
5 Scanner scnr = new Scanner(System. in);
6 /* Type your code here. */
8 VendingMachine v1 = new Vending Machine();
9 v1.purchase() = scnr. nextint(); 10
10 v1.purchase() = scnr. nextint();
11 v1.restock(20);
12 v1.report();
13 }
14 }
Current file: Vending Machine. java
1 // simulates a simple vending machine with operations to purchase drinks and check inventory. 2 public class VendingMachine {
3
4 // number of bottle in stock
5 private int bottles;
6
7 // initial inventory is 20
8 public Vending Machine() {
9 bottles = 20;
10 }
11 public void purchase(int amount) {
12
13 bottles = bottles - amount;
14 }
15
16 public int getInventory (){
17 return bottles;
18 }
19
20 public void restock(int amount) {
21 bottles = bottles + amount; }
22
23
24 public void report({
25 System. out. println("Inventory: " + bottles + bottles + " bottles");
26 }
27
28 }
29

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:30
Why would a programmer use the logical operator and in an if statement? a: when an action is to be taken that requires both conditions to be falseb: when an action is to be taken that requires both conditions to be truec: when an action is to be taken that requires the first condition to be falsed: when an action is to be taken that requires the second condition to be truei took the test and the answer is b.
Answers: 3
question
Computers and Technology, 24.06.2019 07:00
Why would a business likely use a java applet - to back up their data files for the business - to create a program that a customer can launch in their web browser - to create music on a powerpoint presentation - to organize files on their company directory
Answers: 3
question
Computers and Technology, 24.06.2019 09:00
Why might you chose to crest a function resume
Answers: 1
question
Computers and Technology, 26.06.2019 00:00
If an object moves without rotation or angular displacement, it is called translation. true or false
Answers: 1
You know the right answer?
LAB: Vending machine Given two integers as user inputs that represent the number of drinks to buy a...
Questions
question
Mathematics, 08.06.2021 20:20
question
Mathematics, 08.06.2021 20:20
question
Mathematics, 08.06.2021 20:20
question
Mathematics, 08.06.2021 20:20
question
Mathematics, 08.06.2021 20:20
question
English, 08.06.2021 20:20
question
Mathematics, 08.06.2021 20:20