Vending Machine – Part 1
Java Bootcamp Resources ->
Module 2 ->
7. The World of Objects, open the folder:
main() method should contain a welcome message and a commented array.
Based on the requirements, we can classify two types of objects:
We can describe each item using three fields:
The vending machine is identified by the items that it manages. It also performs the action of dispensing an item.
The tasks in this workbook apply to the
Task 1 – Fields
Add the necessary fields to the
class. Protect each field using the
Task 2 – The Big 3
If a class has fields, you need to apply the Big 3.
So, add a constructor, getters, and setters.
Task 3 – Copy Constructor
To avoid the reference trap, we need a way to copy
So, add a copy constructor.
Task 4 – toString
Every class that models an object should have a
toString method to your class, and
String that adheres to this format:
<name>: <price> (<quantity>)
Task 5 – Test your code.
main(), create a new object of the
Itemclass. Feel free to pass random values to the constructor.
Then, print the object.