Question: Goal: test the VendingMachine Class Test Files:- Write a traditional test class named Test1 that tests all the public methods of the VendingMachine class. Write



Goal: test the VendingMachine Class
Test Files:-
- Write a traditional test class named Test1 that tests all the public methods of the VendingMachine class.
- Write a unit test class named Test2 that tests all the public methods of the VendingMachine class.
- Because each method provides a different message, to fully test the getMessage instance variable, for full credit test it after each instance variable that changes the message.
// VendingMachine source code for Project 3 // Allow users to insert coins and purchase // candy bars. public class VendingMachine { // Price of candy bar. final private int CANDY_BAR_PRICE = 75; // Amount deposited for purchase in cents. private int amt ForPurchase; // Number of candy bars currently in vending machine. private int numCandyBars; // Message displayed after action taken. private String message; // Constructor for VendingMachine class. public VendingMachine() { this. amt ForPurchase = 0; this.numCandyBars = 0; this.message = "Vending machine initialized."; // Getter for amt For Purchase instance variable. public int getAmtForPurchase() { return this. amt For Purchase; // Getter for numCandyBars instance variable. public int getNumCandyBars() { return this.numCandy Bars; // Getter for message instance variable. public String getMessage() { return this.message; // Add 5 cents to amount deposited for purchase. public void depositNickel() { this. amt For Purchase += 5; this.message = "Nickel deposited."; // Add 10 cents to amount deposited for purchase. public void depositDime() { this. amt ForPurchase += 10; // Add 5 cents to amount deposited for purchase. public void depositNickel() { this. amt For Purchase += 5; this.message = "Nickel deposited."; // Add 10 cents to amount deposited for purchase. public void depositDime() { this. amt For Purchase += 10; this.message = "Dime deposited."; // Add 25 cents to amount deposited for purchase. public void depositQuarter() { this. amt ForPurchase += 25; this.message = "Quarter deposited."; // Purchase candy bar if amount for purchase is enough. public void purchaseCandyBar() { if (this.amt ForPurchase >= CANDY_BAR_PRICE && this.numCandy Bars > 0) { this.amt ForPurchase -= CANDY_BAR_PRICE; this.numCandyBars--; this.message = "Candy bar dispensed"; else if (this.amtForPurchase = CANDY_BAR_PRICE && this.numCandy Bars > 0) { this.amt ForPurchase -= CANDY_BAR_PRICE; this.numCandyBars--; this.message = "Candy bar dispensed"; else if (this.amtForPurchase
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
