Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:00, Treezy11
In outlook how can cherie look at the details of an event that appears on the month view of her calendar? check all that apply. by switching to the detail view by switching to the week view by switching to the day view by right-clicking on the event by double-clicking on the event by highlighting the event
Answers: 2
image
Computers and Technology, 22.06.2019 06:30, westjayson69
Requirement types discussed during software development include functional and color scheme nonfunctional and code style constraint and nonfunctional fashionable and functional.
Answers: 2
image
Computers and Technology, 22.06.2019 18:00, alyssacyamamoto8050
Budgets you to do all of the following expect a) send frivolously b) avoid over spending c) gain financial independence d) examine your priorities and goals
Answers: 2
image
Computers and Technology, 23.06.2019 23:30, huangjianhe135
The keyboard usually has six rows of keys. which of the following is not one of the key group categories? letter keys number keys control keys graphic keys
Answers: 1
Do you know the correct answer?
LAB: Vending machine Given two integers as user inputs that represent the number of drinks to buy a...

Questions in other subjects:

Konu
Mathematics, 15.07.2020 18:01