{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

VendingMachine

VendingMachine - int slot = 0 int q = quantity...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
public class VendingMachine { int numslot; int maxperslot; double cash; int qty; int q; int n; int s; int slot1; String product; double price; public int[] slot; public String[] Prod; public double[] ProdPrice; public int[] Prodqty; public VendingMachine(int numslots, int maxperslot, double cash){ numslot = numslots; this.maxperslot = maxperslot; this.cash = cash; slot = new int[numslot]; Prod = new String[numslot]; ProdPrice = new double[numslot]; Prodqty = new int[numslot]; } public void setProduct(int slot, String product, double price){ slot1= slot; this.product = product; this.price = price; slot =0; while (slot < numslot){ int qty = getQuantity(slot); if (qty > 0){ qty = 0; } slot++; } } public void restockProduct(String product, int quantity){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int slot = 0; int q = quantity; while (slot < numslot){ if (product.equals(Prod[slot])){ while ((Prodqty[slot] < maxperslot) && (q > 0)) { slot++; q--; } } slot++; } } public double getCashOnHand(){ return (cash); } public int getQuantity(int slot) { return (Prodqty[slot]); } public int getQuantity(String product) { int n = 0; int count = 0; int s = 0; while (n <= numslot) { if (product.equals(Prod[n])) { count = count + Prodqty[n]; s++; } if (s > 0){ return(count); } else { return(0); } } return -1; } public boolean buyItem(int slot) { if (Prodqty[slot] >= 0) { Prodqty[slot]--; cash = cash + ProdPrice[slot]; return (true); } else { return (false); } } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

VendingMachine - int slot = 0 int q = quantity...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online