Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a class called VendingMachine that simulates an imaginary vending machin

ID: 3639009 • Letter: D

Question

Develop a class called VendingMachine that simulates an imaginary vending machine using arrays. A user can buy a bottle of water ($1.50), a bottle of coffee ($2.00), a chip ($1.00), and a chocolate bar ($2.50) using the machine. The user can buy severalitem(s) if they are available in the machine and should pay for the items with either a debit card (PIN: 7777) or a credit card (ZIP code: 93955).

Additionally, an administrator of the machine can reset and refill the machine.


------------------------------------------------------------------------------------
Demo Program: The following code presents a demo program that uses the VendingMachine class.

public class VendingMachineDemo
{
public static void main(String[] args)
{
VendingMachine machine1 = new VendingMachine();
VendingMachine machine2 = new VendingMachine(200, “Library”);
System.out.println("===== Welcome to the Vending Machine =====");
System.out.println(machine1);
System.out.println(machine2);
System.out.println(machine1.equals(machine2));
machine1.setNumber(100);
machine1.setLocation(“abc104”);
machine1.reset(5, 7, 3, 10); // In this method, we assume that a machine
// administrator can reset the contents of
// a machine.
machine1.displayMenu()
machine1.buyItems();
if(machine1.buyItems(1, 4) == false) {
System.exit(1);
}
machine1.returned(1, 2);
machine1.returned(2, 2);
machine1.buyItems(3, 5);
if(machine1.payment()) {
machine1.displayReceipt();
}
else {
System.out.println("Invalid payment.");
System.exit(1);
}
machine1.addItems(5,5,5,5); // A system admin cam add items to the machine
machine1.status();
System.out.println("===== Thank you! =====");
}
}

Explanation / Answer

Do you mind if I post the answer in your comments page tomorrow? I'll do it anyways.