x.Hmelp with three of the methods I have to implement. 1.) /** * The most recent
ID: 3618493 • Letter: X
Question
x.Hmelp with three of the methods I have to implement.1.)
/**
* The most recent <code>Product</code> sold. Returns <code>Product.NO_PRODUCT</code>
* if the most recent call to <code>dispenseItem</code> did not successfully
* dispense an item or if <code>dispenseItem</code> has not yet been invoked.
*/
public Product productDispensed () {
return ;
2.) /**
* The coins most recently returned, from an invocation of <code>returnCoins</code>
* or <code>dispenseItem</code>.
*/
public Change coinsReturned () {
this.change = coinDeposited.coins();
3.) /**
* An item can be dispensed from the specified <code>Bin</code>:
* the <code>Bin</code> is not empty and appropriate coins
* have been deposited.
* @require <code>1 <= bin && bin <= NUMBER_OF_PRODUCTS</code>
*/
private boolean canDispense (Bin bin) {
package c1581.lab10;
/**
* A coin-operated vending machine with three products to dispense.
*/
public class VendingMachine {
private Bin bin1;
private Bin bin2;
private Bin bin3;
private CoinBox coinTill;
private CoinBox coinDeposited;
private Change change;
private Product product;
/**
* The number of products this <code>VendingMachine</code> can dispense.
*/
public final static int NUMBER_OF_PRODUCTS = 3;
public final static int BIN1 = 1;
public final static int BIN2 = 2;
public final static int BIN3 = 3;
/**
* Create a new <code>VendingMachine</code>, initially empty. Each bin contains
* 0 instances of the virtual product, <code>Product.NO_PRODUCT</code>.
*/
public VendingMachine () {
this.bin1 = new Bin();
this.bin2 = new Bin();
this.bin3 = new Bin();
this.coinTill = new CoinBox();
this.coinDeposited = new CoinBox();
this.change = null;
this.product = Product.NO_PRODUCT;
}
/**
* Load a bin with the specified amount of a <code>Product</code>. Any coins
* deposited since the last sale are returned.
* @require <code>1 <= bin && bin <= NUMBER_OF_PRODUCTS<br>
* 0 <= quantity && quantity <= this.maxQuantity(bin)</code>
* @ensure <code>this.product(bin).equals(product)<br>
* this.amountDeposited() == 0</code>
*/
public void load (int bin, Product product, int quantity) {
}
/**
* The maximum number of items the specified bin can contain.
* @require <code>1 <= bin && bin <= NUMBER_OF_PRODUCTS</code>
* @ensure <code>this.maxQuantity(bin) >= 0</code>
*/
public int maxQuantity (int bin) {
return Bin.MAX_QUANTITY;
}
/**
* The <code>Product</code> in the specified bin.
* @require <code>1 <= bin && bin <= NUMBER_OF_PRODUCTS</code>
*/
public Product product (int bin) {
return selectBin(bin).product();
}
/**
* A nickel is deposited in this <code>VendingMachine</code>.
*/
public void acceptNickel () {
this.coinTill.add(Change.NICKEL);
}
/**
* A dime is deposited in this <code>VendingMachine</code>.
*/
public void acceptDime () {
this.coinTill.add(Change.DIME);
}
/**
* A quarter is deposited in this <code>VendingMachine</code>.
*/
public void acceptQuarter () {
this.coinTill.add(Change.QUARTER);
}
/**
* The amount deposited since the last sale, in cents.
* @ensure <code>this.amountDeposited() >= 0</code>
*/
public int amountDeposited () {
return coinDeposited.coins().value();
}
/**
* The amount collected from product sales, in cents. This value
* is reset to 0 when the till is emptied.
*/
public int amountInTill () {
return coinTill.coins().value();
}
/**
* Return any coins depostied since the last sale.
* @ensure <code>this.amountDeposited() == 0</code>
*/
public void returnCoins () {
this.change = coinDeposited.coins();
coinDeposited.reset();
}
/**
* Clear the till of all coins. Any coins deposited since the last sale are
* returned.
* @ensure <code>this.amountInTill() == 0<br>
* this.amountDeposited() == 0</code>
*/
public void emptyTill () {
this.returnCoins();
coinTill.remove(change);
coinTill.reset();
}
/**
* Dispense an item from the specified bin if the bin is not empty and if
* appropriate coins have not been deposited.
* @require <code>1 <= bin && bin <= NUMBER_OF_PRODUCTS</code>
*/
public void dispenseItem (int bin) {
selectBin(bin).dispense();
}
/**
* The most recent <code>Product</code> sold. Returns <code>Product.NO_PRODUCT</code>
* if the most recent call to <code>dispenseItem</co
Explanation / Answer
Can you please post the problem statement..?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.