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

Public Member Functions

String execute (VendingMachine v, String[] cmdParts)
 
- Public Member Functions inherited from Command

Detailed Description

Definition at line 3 of file CmdRejectCoins.java.

Member Function Documentation

◆ execute()

String CmdRejectCoins.execute ( VendingMachine v,
String[] cmdParts )
inline

Implements Command.

Definition at line 5 of file CmdRejectCoins.java.

5 {
6 int total = v.getTotalInsertedCoinsAmount();
7 if (total == 0) {
8 return "Rejected no coin!";
9 }
10 else {
11 String return_text = "Rejected ";
12 // only $1, $2, $5, $10 coins are accepted
13 // print the coins in the order of $1, $2, $5, $10
14 ArrayList<ArrayList<Integer>> coins_list = v.getGroupedInsertedCoins();
15 for (int i = 0; i < 4; i++) {
16 for (Integer c : coins_list.get(i)) {
17 return_text += "$" + c + ", ";
18 }
19 }
20 // remove the last ", " and add "."
21 return_text = return_text.substring(0, return_text.length() - 2) + ".";
22 return_text += " $" + total + " in total.";
23 v.dumpAllCoins();
24 return return_text;
25 }
26 }
ArrayList< ArrayList< Integer > > getGroupedInsertedCoins()
int getTotalInsertedCoinsAmount()

References VendingMachine.dumpAllCoins(), VendingMachine.getGroupedInsertedCoins(), and VendingMachine.getTotalInsertedCoinsAmount().

Here is the call graph for this function:

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