Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*This program needs to simulate a vending machine. In java using this code a vending machine program that uses an Interface. public class Inventory {

*This program needs to simulate a vending machine.

In java using this code a vending machine program that uses an Interface.

public class Inventory {

private Map inventory = new HashMap();

public int getQuantity(T product) {

Integer value = inventory.get(product);

return value == null ? 0 : value;

}

public void add(T product) {

int count = inventory.get(product);

inventory.put(product, count + 1);

}

public void deduct(T product) {

if (hasItem(product)) {

int count = inventory.get(product);

inventory.put(product, count - 1);

}

}

public boolean hasItem(T product) {

return getQuantity(product) > 0;

}

public void clear() {

inventory.clear();

}

public void put(T product, int quantity) {

inventory.put(product, quantity);

}

}

public enum Product {

COKE("Coke", 25), PEPSI("Pepsi", 35), SODA("Soda", 45);

private String name;

private int price;

private Product (String name, int price) {

this.name = name;

this.price = price;

}

public String getName() {

return name;

}

public long getPrice() {

return price;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

Find dy/dx if x = te, y = 2t2 +1

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago