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, 21.06.2019 21:30
Asuccessful format string attack attempted to steal user account information by reading from unauthorized memory. answer the followings with proper explanation a)this attack will lead to violation of which security policies?
Answers: 2
question
Computers and Technology, 22.06.2019 05:00
Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. after the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. declare any variables that are needed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system.in); is given.
Answers: 3
question
Computers and Technology, 22.06.2019 07:30
Jasper and samantha are in a robotics competition. the guidelines state that the robots should be able to move a 10-gram weight at least 2 meters and turn in a circle. jasper and samantha have already built the robot. which step of the design process should they follow next to decide whether their robot meets the minimum criteria for the competition?
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Design a class tictactoe that: holds the following information about the game: two-dimensional array (3 by 3), and winner. add additional variables as needed. includes the functions to perform the various operations on objects. for example, function to print the board, getting the move, checking if move is valid, determining if there is a winner after each move. add additional operations as needed. includes constructor(s). write the functions of the class, and write a program that uses the class. the program should declare an object of type tictactoe. the program will create the board and store it in the array. the program will allow two players to play the tic-tac-toe game. after every valid move update the array, check if there is a winner. if there is no winner and no tie, then print the board again to continue.
Answers: 2
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
Social Studies, 10.12.2019 02:31
Questions on the website: 13722362