Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you need to design and implement a single class, VendingMachine . The Vending Machine Problem: Overview You are required to develop an object-oriented program solving

you need to design and implement a single class, VendingMachine.

The Vending Machine Problem: Overview

You are required to develop an object-oriented program solving a (simplified) vending machine (VM) problem:

  • There are four products offered (attend to the exact spellings): o "Cheetos Crunchy"
  • o "Coke"
  • o "Doritos Nacho Cheese"
  • o "Red Bull"
  • The VM's LED screen always displays a message: o When first created, the message is "Empty VM Started"
  • o The message only changes when the add or dispense operation (described below) is invoked.
  • Given an VM instance, say vm, there are five operations supported: o Get the current message displayed on the VM: vm.getMessage().
  • o Check the overall stock of the current VM: vm.checkStock().
  • o Given a product name, check its current stock, e.g., vm.checkStock("Coke")
  • o Given a product name, add units to its stock, e.g., vm.add("Coke", 5)
  • o Given a product name, dispense units from its stock, e.g., vm.dispense("Coke", 2)
  • 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

Task 1: Implement the VendingMachine class

Step 1: In IntelliJ IDEA create a new project named "lab4" on the "lab4" folder extracted from lab4.zip. You may refer to previous lab handouts for the detail steps on how to do this. However, at this point, we hope that you can already handle this without having to look at all the screenshots!

Step 2: Read and analyze the test cases in TestVendingMachine.java carefully to infer the expected behaviours of the VendingMachine class.

Step 3: Implement the VendingMachine, including all the instance variables and methods, according to the design that you completed in Task 0. Below are the methods that require implementation. You may also add other helper methods as you see necessary.

  • Constructor(s)
  • add
  • dispense
  • checkStock
  • getMessage

Requirements:

  • Any use of Java library classes or methods (e.g., ArrayList) is forbidden. That is, there must not be any import statement at the beginning of this class. Violation of this requirement will result in a 50% penalty of your marks.
  • It is OK to use primitive arrays such as int[] and String[].

Task 2: Test Your Implementation Using JUnit Test Cases

Make sure your implementation passes all the given JUnit test cases. In addition, add your own test cases to test it more thoroughly. Note that passing only the provided test cases does not guarantee full marks.

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_2

Step: 3

blur-text-image_3

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

Introduction To Health Care Management

Authors: Sharon B. Buchbinder, Nancy H. Shanks

3rd Edition

128408101X, 9781284081015

More Books

Students also viewed these Programming questions

Question

Evaluate the permutations 10 6. Plo 9

Answered: 1 week ago

Question

Evaluate the permutations 5. P 3

Answered: 1 week ago