Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions