Computers and Technology
Computers and Technology, 19.01.2021 19:30, arely30

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
LAB ACTIVITY 7.13.1: LAB: Vending machine
Current file: LabProgram. java Load default template...
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
7 /* Type your code here.*/ 8
8 VendingMachine v1 = new Vending Machine();
9 v1.purchase() = scnr. nextint();
10 v1.purchase() = scnr. nextint();
11 v1.restock(20);
12 v1.report();
13 }
14 }
15
LAB ACTIVITY 7.13.1: LAB: Vending machine
File is marked as read only 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
12 public void purchase(int amount) {
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: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 08:30, electrofy456
Active listen eliminates barries to communication true or false
Answers: 1
image
Computers and Technology, 23.06.2019 01:50, akornegay2
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. double the number. b. reverse the digits of the number. c. raise the number to the power of 2, 3, or 4. d. sum the digits of the number. e. if the number is a two-digit number, then raise the first digit to the power of the second digit. f. if the number is a three-digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit. after performing an operation if the number is less than 10, add 10 to the number. also, after each operation determine if the number is prime. each successive operation should be performed on the number generated by the last operation. your program should not contain any global variables and each of these operations must be implemented by a separate function. also, your program should be menu driven. 7. (fraction calculator) write a program that
Answers: 1
image
Computers and Technology, 23.06.2019 03:00, SKYBLUE1015
What are the different parts of computer
Answers: 2
image
Computers and Technology, 24.06.2019 02:20, isabelsmhl
Peter is thinking of a number which isless than 50. the number has 9 factors. when he adds 4 to the number, itbecomes a multiple of 5. what is thenumber he is thinking of ?
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
History, 11.07.2019 16:40
Konu
Biology, 11.07.2019 16:40