Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im creating a vending machine java project that uses generics and an Interface. Im looking for how to implement this into my code so far

Im creating a vending machine java project that uses generics and an Interface. Im looking for how to implement this into my code so far as a payment method

image text in transcribed

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;

}

}

Smart Card Reader boolean: check Cardvalidity0 read CardAmount 0 update CardAmount insertCard0 releaseCard()

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

Step: 3

blur-text-image

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions