Question: in Java please 2.3 The Vending Machine Problem You are required to develop an object-oriented program solving a (simplified) vending machine (VM) problem: There are




in Java please
2.3 The Vending Machine Problem You are required to develop an object-oriented program solving a (simplified) vending machine (VM) problem: There are four products offerred (attend to the exact spellings): "Coke" "Orange Juice" "Kitkat Chunky Bar" "Lay's Classic Chips" In case you are a big fan of M&M's chocolate bags: unfortunately, the kind of VMs under consideration does not offer them! AYA SAN Tuy Site On Sun A. Sun Sun The VM's LED screen displays the status of the VM: - When first created, the status is "Empty VM Started" - The status only changes when the add or dispense operation (described below) is invoked. Given an VM instance, say vm, there are five operations supported: Check the status of the current VM: vm.checkStatus(). Check the stock of the current VM: vm.checkStock(). Given a product name: Add units to its stock, e.g., vm.add("Coke", 5) - Dispense units from its stock, e.g., vm. dispense("Coke", 2) Check its current stock, e.g., vm.checkStock("Coke") Input names to the add and dispense operations may be invalid, in which case you need to return error messages accordingly. Input units to the add and dispense operations are always valid: you need not worry about non-positive or too-large values. - @Test public void test_VendingMachine_01a() { VendingMachine vm = new VendingMachine(); String result = vm.checkStatus(); assertEquals("Empty VM Started", result); } @Test public void test_VendingMachine_01b1() { VendingMachine vm = new VendingMachine(); String result = vm.checkStock("Coke"); assertEquals("Coke (0)", result); result = vm.checkStatus(); // status remains initialized assertEquals("Empty VM Started", result); } @Test public void test_VendingMachine_01b2() { VendingMachine vm = new VendingMachine(); String result = vm.checkStock ("Orange Juice"); assertEquals("Orange Juice (0)", result); result = vm.checkStatus(); // status remains initialized assertEquals("Empty VM Started", result); } @Test public void test_VendingMachine_01b3() { VendingMachine vm = new VendingMachine(); String result = vm.checkStock("Kitkat Chunky Bar"); assertEquals("Kitkat Chunky Bar (0)", result); result = vm.checkStatus(); // status remains initialized assertEquals("Empty VM Started", result); @Test public void test_VendingMachine_0164() { VendingMachine vm = new VendingMachine(); String result = vm.checkStock("Lay's Classic Chips"); assertEquals("Lay's Classic Chips (0)", result); result = vm.checkStatus(); // status remains initialized assertEquals("Empty VM Started", result); } @Test public void test_VendingMachine_01b5() { VendingMachine vm = new VendingMachine(); String result = vm.checkStock("Lay's BBQ Chips"); // invalid product name assertEquals("Invalid product: Lay's BBQ Chips", result); // Notice the space between colon (:) and the i result = vm.checkStatus(); // status remains initialized assertEquals("Empty VM Started", result); } @Test public void test_VendingMachine_01c() { VendingMachine vm = new VendingMachine(); String result = vm.checkStock(); assertEquals("Stock: Coke (0), Orange Juice (0), Kitkat Chunky Bar (0), Lay's Classic Chips (0)", result) } /* * Tests related to adding stock to the vending machine */ ATest vm.add("Kitkat Chunky Bar", 5); // this changes the status result = vm.checkStatus(); assertEquals("Product added: Kitkat Chunky Bar (5)", result); // Notice the space after the colon ":" and before the result = vm.checkStock("Kitkat Chunky Bar"); assertEquals("Kitkat Chunky Bar (5)", result); result = vm.checkStock(); assertEquals("Stock: Coke (5), Orange Juice (5), Kitkat Chunky Bar (5), Lay's Classic Chips (0)", result); /* * Add stock of Lay's Classic Chips */ vm.add("Lay's Classic Chips", 5); // this changes the status result = vm.checkStatus(); assertEquals("Product added: Lay's Classic Chips (5)", result); // Notice the space after the colon ":" and before the result = vm.checkStock("Lay's Classic Chips"); assertEquals("Lay's Classic Chips (5)", result); result = vm.checkStock(); assertEquals("Stock: Coke (5), Orange Juice (5), Kitkat Chunky Bar (5), Lay's Classic Chips (5)", result); /* * Add stock of an invalid product */ vm.add("Maltesers Chocolate", 4); // this changes the status result = vm.checkStatus(); assertEquals("Invalid product: Maltesers Chocolate", result); // Notice the space between colon (:) and the invalid pr result = vm.checkStock("Maltesers Chocolate"); assertEquals("Invalid product: Maltesers Chocolate", result); // Notice the space between colon (:) and the invalid pr result = vm.checkStock(); // stock of existing products remain the same assertEquals("Stock: Coke (5), Orange Juice (5), Kitkat Chunky Bar (5), Lay's Classic Chips (5)", result)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
