Question: Do it in eclipse java and library classes. There are four products offerred (attend to the exact spellings): Hints and Requirements Coke Orange Juice Kitkat
Do it in eclipse java and library classes.
There are four products offerred (attend to the exact spellings):
Hints and Requirements
Coke
Orange Juice
Kitkat Chunky Bar Lays Classic Chips
In case you are a big fan of M & Ms chocolate bags: unfortunately, the kind of VMs under consideration does not offer them!
The VMs 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.
package junit_tests;
import static org.junit.Assert.*;
import org.junit.Test;
/*
* Requirement: Any classes you create must reside in the `model` package and be imported properly.
* For example, creating a new class `Foo` in the `model` package should result in:
* import model.Foo;
*/
import model.VendingMachine;
public class TestVendingMachine {
/*
*
* Tests included in this class serve as documentation on how instances of a vending machine work.
*
*
*
*/
/*
* Tests related to an initial, empty vending machine
*/
@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_01b4() {
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 invalid product's name.
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
*/
@Test
public void test_VendingMachine_02() {
VendingMachine vm = new VendingMachine();
/*
* Add stock of Coke
*/
vm.add("Coke", 5); // this changes the status
String result = vm.checkStatus();
assertEquals("Product added: Coke (5)", result); // Notice the space after the colon ":" and before the opening parenthesis "(".
result = vm.checkStock("Coke");
assertEquals("Coke (5)", result);
result = vm.checkStock();
assertEquals("Stock: Coke (5), Orange Juice (0), Kitkat Chunky Bar (0), Lay's Classic Chips (0)", result);
/*
* Add stock of Orange Juice
*/
vm.add("Orange Juice", 5); // this changes the status
result = vm.checkStatus();
assertEquals("Product added: Orange Juice (5)", result); // Notice the space after the colon ":" and before the opening parenthesis "(".
result = vm.checkStock("Orange Juice");
assertEquals("Orange Juice (5)", result);
result = vm.checkStock();
assertEquals("Stock: Coke (5), Orange Juice (5), Kitkat Chunky Bar (0), Lay's Classic Chips (0)", result);
/*
* Add stock of Kitkat Chunky Bar
*/
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 opening parenthesis "(".
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 opening parenthesis "(".
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.dispense("Maltesers Chocolate", 4); // this changes the status
result = vm.checkStatus();
assertEquals("Invalid product: Maltesers Chocolate", result); // Notice the space between colon (:) and the invalid product's name.
result = vm.checkStock("Maltesers Chocolate");
assertEquals("Invalid product: Maltesers Chocolate", result); // Notice the space between colon (:) and the invalid product's name.
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);
}
/*
* Tests related to reducing stock from the vending machine
*/
@Test
public void test_VendingMachine_03() {
VendingMachine vm = new VendingMachine();
/*
* Add stocks of products
*/
vm.add("Coke", 5);
vm.add("Orange Juice", 6);
vm.add("Kitkat Chunky Bar", 7);
vm.add("Lay's Classic Chips", 8);
String result = vm.checkStock();
assertEquals("Stock: Coke (5), Orange Juice (6), Kitkat Chunky Bar (7), Lay's Classic Chips (8)", result);
/*
* Remove stock of Coke
*/
vm.dispense("Coke", 1); // this changes the status
result = vm.checkStatus();
assertEquals("Product removed: Coke (1)", result); // Notice the space after the colon ":" and before the opening parenthesis "(".
result = vm.checkStock("Coke");
assertEquals("Coke (4)", result);
result = vm.checkStock();
assertEquals("Stock: Coke (4), Orange Juice (6), Kitkat Chunky Bar (7), Lay's Classic Chips (8)", result);
/*
* Remove stock of Orange Juice
*/
vm.dispense("Orange Juice", 2); // this changes the status
result = vm.checkStatus();
assertEquals("Product removed: Orange Juice (2)", result); // Notice the space after the colon ":" and before the opening parenthesis "(".
result = vm.checkStock("Orange Juice");
assertEquals("Orange Juice (4)", result);
result = vm.checkStock();
assertEquals("Stock: Coke (4), Orange Juice (4), Kitkat Chunky Bar (7), Lay's Classic Chips (8)", result);
/*
* Remove stock of Kitkat Chunky Bar
*/
vm.dispense("Kitkat Chunky Bar", 3); // this changes the status
result = vm.checkStatus();
assertEquals("Product removed: Kitkat Chunky Bar (3)", result); // Notice the space after the colon ":" and before the opening parenthesis "(".
result = vm.checkStock("Kitkat Chunky Bar");
assertEquals("Kitkat Chunky Bar (4)", result);
result = vm.checkStock();
assertEquals("Stock: Coke (4), Orange Juice (4), Kitkat Chunky Bar (4), Lay's Classic Chips (8)", result);
/*
* Remove stock of Lay's Classic Chips
*/
vm.dispense("Lay's Classic Chips", 4); // this changes the status
result = vm.checkStatus();
assertEquals("Product removed: Lay's Classic Chips (4)", result); // Notice the space after the colon ":" and before the opening parenthesis "(".
result = vm.checkStock("Lay's Classic Chips");
assertEquals("Lay's Classic Chips (4)", result);
result = vm.checkStock();
assertEquals("Stock: Coke (4), Orange Juice (4), Kitkat Chunky Bar (4), Lay's Classic Chips (4)", result);
/*
* Remove stock of an invalid product
*/
vm.dispense("M & M's Chocoloate Bag", 4); // this changes the status
result = vm.checkStatus();
assertEquals("Invalid product: M & M's Chocoloate Bag", result); // Notice the space between colon (:) and the invalid product's name.
result = vm.checkStock("M & M's Chocoloate Bag");
assertEquals("Invalid product: M & M's Chocoloate Bag", result); // Notice the space between colon (:) and the invalid product's name.
result = vm.checkStock(); // stock of existing products remain the same
assertEquals("Stock: Coke (4), Orange Juice (4), Kitkat Chunky Bar (4), Lay's Classic Chips (4)", result);
}
/*
* Additional tests related to using a vending machine
*/
@Test
public void test_VendingMachine_04() {
VendingMachine vm = new VendingMachine();
/* You may add additional, similar tests on other products */
vm.add("Kitkat Chunky Bar", 7);
assertEquals("Kitkat Chunky Bar (7)", vm.checkStock("Kitkat Chunky Bar"));
assertEquals("Stock: Coke (0), Orange Juice (0), Kitkat Chunky Bar (7), Lay's Classic Chips (0)", vm.checkStock());
vm.dispense("Kitkat Chunky Bar", 3);
assertEquals("Kitkat Chunky Bar (4)", vm.checkStock("Kitkat Chunky Bar"));
assertEquals("Stock: Coke (0), Orange Juice (0), Kitkat Chunky Bar (4), Lay's Classic Chips (0)", vm.checkStock());
vm.add("Kitkat Chunky Bar", 5);
assertEquals("Kitkat Chunky Bar (9)", vm.checkStock("Kitkat Chunky Bar"));
assertEquals("Stock: Coke (0), Orange Juice (0), Kitkat Chunky Bar (9), Lay's Classic Chips (0)", vm.checkStock());
}
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
