2.8k views
24 votes
Need this java code its on zybooks. 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 vending machine 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.


the file that comes with it:


// simulates a simple vending machine with operations to purchase drinks and check inventory.

public class vendingmachine {


// number of bottle in stock

private int bottles;


// initial inventory is 20

public vendingmachine(){

bottles = 20;

}


public void purchase(int amount){

bottles = bottles - amount;

}


public int getinventory(){

return bottles;

}


public void restock(int amount){

bottles = bottles + amount;

}


public void report(){

system.out.println("inventory: " + bottles + " bottles");

}


}

User Kenny Body
by
7.1k points

1 Answer

6 votes

Answer:

5 bottles left and plus the amount of water they used

Step-by-step explanation:

User Chao Ruan
by
7.6k points