VendingMachine

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

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 DocumentRight 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 &lt; numslot){ if (product.equals(Prod[slot])){ while ((Prodqty[slot] &lt; maxperslot) &amp;&amp; (q &gt; 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 &lt;= numslot) { if (product.equals(Prod[n])) { count = count + Prodqty[n]; s++; } if (s &gt; 0){ return(count); } else { return(0); } } return -1; } public boolean buyItem(int slot) { if (Prodqty[slot] &gt;= 0) { Prodqty[slot]--; cash = cash + ProdPrice[slot]; return (true); } else { return (false); } } }...
View Full Document

This note was uploaded on 07/12/2009 for the course CS 111 taught by Professor Hari during the Fall '08 term at Rutgers.

Page1 / 2

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

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

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