COMP2396
Loading...
Searching...
No Matches
VendingMachine Class Reference
Collaboration diagram for VendingMachine:

Public Member Functions

 VendingMachine ()
 
void addProduct (Product p)
 
void deductProductQuantity (Product p)
 
void dumpAllCoins ()
 
ArrayList< ArrayList< Integer > > getGroupedInsertedCoins ()
 
ArrayList< Integer > getInsertedCoins ()
 
Product getProduct (String name)
 
int getTotalInsertedCoinsAmount ()
 
void insertCoin (Integer c)
 
void removeCoin (Integer c)
 

Private Attributes

ArrayList< Integer > insertedCoins
 
ArrayList< Productproducts
 

Detailed Description

Definition at line 4 of file VendingMachine.java.

Constructor & Destructor Documentation

◆ VendingMachine()

VendingMachine.VendingMachine ( )
inline

Definition at line 11 of file VendingMachine.java.

11 {
12 insertedCoins = new ArrayList<Integer>();
13 products = new ArrayList<Product>();
14 }
ArrayList< Integer > insertedCoins
ArrayList< Product > products

References insertedCoins, and products.

Member Function Documentation

◆ addProduct()

void VendingMachine.addProduct ( Product p)
inline

Definition at line 16 of file VendingMachine.java.

16 {
17 products.add(p);
18 }

References products.

Referenced by Main.main().

Here is the caller graph for this function:

◆ deductProductQuantity()

void VendingMachine.deductProductQuantity ( Product p)
inline

Definition at line 35 of file VendingMachine.java.

35 {
36 p.setQuantity(p.getQuantity() - 1);
37 }
int getQuantity()
Definition Product.java:24
void setQuantity(int quantity)
Definition Product.java:29

References Product.getQuantity(), and Product.setQuantity().

Referenced by CmdPurchase.execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpAllCoins()

void VendingMachine.dumpAllCoins ( )
inline

Definition at line 31 of file VendingMachine.java.

31 {
32 insertedCoins.clear();
33 }

References insertedCoins.

Referenced by CmdPurchase.execute(), and CmdRejectCoins.execute().

Here is the caller graph for this function:

◆ getGroupedInsertedCoins()

ArrayList< ArrayList< Integer > > VendingMachine.getGroupedInsertedCoins ( )
inline

Definition at line 44 of file VendingMachine.java.

44 {
45 ArrayList<ArrayList<Integer>> coins_list = new ArrayList<ArrayList<Integer>>();
46 for (int i = 0; i < 4; i++) {
47 coins_list.add(new ArrayList<Integer>());
48 }
49 for (Integer c : insertedCoins) {
50 if (c == 1) {
51 coins_list.get(0).add(c);
52 } else if (c == 2) {
53 coins_list.get(1).add(c);
54 } else if (c == 5) {
55 coins_list.get(2).add(c);
56 } else if (c == 10) {
57 coins_list.get(3).add(c);
58 }
59 }
60 return coins_list;
61 }

References insertedCoins.

Referenced by CmdRejectCoins.execute().

Here is the caller graph for this function:

◆ getInsertedCoins()

ArrayList< Integer > VendingMachine.getInsertedCoins ( )
inline

Definition at line 40 of file VendingMachine.java.

40 {
41 return insertedCoins;
42 }

References insertedCoins.

◆ getProduct()

Product VendingMachine.getProduct ( String name)
inline

Definition at line 71 of file VendingMachine.java.

71 {
72 for (Product p : products) {
73 if (p.getName().equals(name)) {
74 return p;
75 }
76 }
77 return null;
78 }

References products.

Referenced by CmdCheckProductInfo.execute(), and CmdPurchase.execute().

Here is the caller graph for this function:

◆ getTotalInsertedCoinsAmount()

int VendingMachine.getTotalInsertedCoinsAmount ( )
inline

Definition at line 63 of file VendingMachine.java.

63 {
64 int total = 0;
65 for (Integer c : insertedCoins) {
66 total += c;
67 }
68 return total;
69 }

References insertedCoins.

Referenced by CmdInsertCoin.execute(), CmdPurchase.execute(), and CmdRejectCoins.execute().

Here is the caller graph for this function:

◆ insertCoin()

void VendingMachine.insertCoin ( Integer c)
inline

Definition at line 20 of file VendingMachine.java.

20 {
21 insertedCoins.add(c);
22 }

References insertedCoins.

Referenced by CmdInsertCoin.execute().

Here is the caller graph for this function:

◆ removeCoin()

void VendingMachine.removeCoin ( Integer c)
inline

Definition at line 27 of file VendingMachine.java.

27 {
28 insertedCoins.remove(c);
29 }

References insertedCoins.

Member Data Documentation

◆ insertedCoins

ArrayList<Integer> VendingMachine.insertedCoins
private

◆ products

ArrayList<Product> VendingMachine.products
private

Definition at line 9 of file VendingMachine.java.

Referenced by VendingMachine(), addProduct(), and getProduct().


The documentation for this class was generated from the following file: