1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Reptile [31]
3 years ago
10

Given two integers as user inputs that represent the number of drinks to buy and the number of bottles to restock, create a Vend

ingMachine 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

Need this answer in java! !!!!!!!!!!!!
Computers and Technology
1 answer:
Zanzabum3 years ago
7 0

Answer:

import java.util.Scanner;

class Main {

 public static void main (String args[])

 {

   Scanner input = new Scanner(System.in);

   VendingMachine machine = new VendingMachine(20);

   System.out.print("Enter nr to purchase: ");

   int nrPurchased = input.nextInt();

   System.out.print("Enter nr to re-stock: ");

   int nrRestock = input.nextInt();

   machine.Transaction(nrPurchased, nrRestock);

   input.close();

 }

}

class VendingMachine {

 private int inventory;

 public VendingMachine(int initialInventory) {

   inventory = initialInventory;

 }

 public void Transaction(int nrToBuy, int nrToRestock) {

   inventory += nrToRestock - nrToBuy;

   System.out.printf("Inventory: %d bottles.\n", inventory);

 }

}

You might be interested in
HELPPP!!! ASAP *What are the purposes of a good web page?*
Brrunno [24]

I would say functional and straightforward

4 0
3 years ago
How does culture affect your life
777dan777 [17]
Culture identifies who you are, what you value, and how you act. 
5 0
3 years ago
Ms. Rogers wants to see the names of all the students who scored below 25 on the test. Which of these custom options will help h
photoshop1234 [79]
B Is less than because it says below

6 0
3 years ago
In a linked chain implementation of a stack ADT the performance of popping am emtry from the stack is
Mice21 [21]

Answer:

B.O(1)

Explanation:

When we are implementing ADT stack using linked chain we can pop an entry from the stack having O(1) time complexity because in linked chain we have the head or top pointer in linked chain only.Popping and pushing in stack happens on only one end that is top.So we have move to move top in linked chain to the next and delete prev node.

8 0
3 years ago
Why linked list is better than an array?
katrin [286]
In conclusion there are many different data structures. Each data structure has strengths and weaknesses which affect performance depending on the task. Today, we explored two data structures: arrays and linked lists. Arrays allow random access and require less memory per element (do not need space for pointers) while lacking efficiency for insertion/deletion operations and memory allocation. On the contrary, linked lists are dynamic and have faster insertion/deletion time complexities. However, linked list have a slower search time and pointers require additional memory per element in the list. Figure 10 below summarizes the strength and weakness of arrays and linked lists.
8 0
3 years ago
Other questions:
  • Your network employs basic authentication that centers on usernames and passwords. However, you have two ongoing problems. The f
    13·1 answer
  • You are a project manager tasked to implement a critical application in a reputed bank. A client review indicates that you could
    11·2 answers
  • What type of hardware and software does Instagram use?
    9·2 answers
  • Amanda needs to create an informative print brochure for her local library’s fundraiser dinner. What critical detail must she ha
    14·2 answers
  • In a linked chain implementation of a queue, the performance of the enqueue operation
    10·1 answer
  • In 2d design, form makes what possible?
    15·1 answer
  • In Microsoft Excel, you are working with a large worksheet. Your row headings are in column A. Which command(s) should be used t
    7·1 answer
  • Zachary drinks 2 cups of milk per day. He buys 6 quarts of milk. How many days will his 6 quarts of milk last?
    12·1 answer
  • Are there any Potential Dangers in Artificial Intelligence?
    11·2 answers
  • What is the difference between an html opening tag and a closing tag?.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!