COMP2396
Loading...
Searching...
No Matches
Main Class Reference

Static Public Member Functions

static void main (String[] args) throws IOException
 
static void main (String[] args)
 

Static Private Member Functions

static void toPikachu (Pikachu pkm)
 
static void toSquirtle (Squirtle pkm)
 

Detailed Description

Definition at line 3 of file Main.java.

Member Function Documentation

◆ main() [1/2]

static void Main.main ( String[] args) throws IOException
inlinestatic

Definition at line 5 of file Main.java.

5 {
6 BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
7 String inputLine = "";
8
10
11 // Adds products to the vending machine
12 v.addProduct(new Product("Cocacola", 4, 1)); // Price: $4, Quantity: 1
13 v.addProduct(new Product("Pepsi", 5, 3)); // Price: $5, Quantity: 3
14
15 System.out.println("Welcome to COMP2396B Assignment 3 - Vending Machine");
16
17 // Reads user inputs continuously
18 while (true) {
19 inputLine = input.readLine();
20
21 // Split the input line
22 String[] cmdParts = inputLine.split(" ");
23
24 Command cmdObj = null;
25
26 if (cmdParts[0].equalsIgnoreCase("Exit")) {
27 break;
28 } else if (cmdParts[0].equalsIgnoreCase("Check")) {
29 cmdObj = new CmdCheckProductInfo();
30 } else if (cmdParts[0].equalsIgnoreCase("Insert")) {
31 cmdObj = new CmdInsertCoin();
32 } else if (cmdParts[0].equalsIgnoreCase("Reject")) {
33 cmdObj = new CmdRejectCoins();
34 } else if (cmdParts[0].equalsIgnoreCase("Buy")) {
35 cmdObj = new CmdPurchase();
36 } else {
37 System.out.println("Unknown user command.");
38 }
39
40 if (cmdObj != null) {
41 System.out.println(cmdObj.execute(v, cmdParts));
42 }
43
44 inputLine = "";
45 }
46
47 System.out.println("Bye");
48 }
void addProduct(Product p)
String execute(VendingMachine v, String[] cmdParts)

References VendingMachine.addProduct(), and Command.execute().

Here is the call graph for this function:

◆ main() [2/2]

static void Main.main ( String[] args)
inlinestatic

Definition at line 10 of file Main.java.

10 {
11 Ditto pkm = new ShinyDitto();
12 toPikachu(pkm);
13 toSquirtle(pkm);
14 }
static void toSquirtle(Squirtle pkm)
Definition Main.java:6
static void toPikachu(Pikachu pkm)
Definition Main.java:2

References toPikachu(), and toSquirtle().

Here is the call graph for this function:

◆ toPikachu()

static void Main.toPikachu ( Pikachu pkm)
inlinestaticprivate

Definition at line 2 of file Main.java.

2 {
4 }
void releaseElectricity()

References Pikachu.releaseElectricity().

Referenced by main().

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

◆ toSquirtle()

static void Main.toSquirtle ( Squirtle pkm)
inlinestaticprivate

Definition at line 6 of file Main.java.

6 {
7 pkm.sprayWater();
8 }
void sprayWater()

References Squirtle.sprayWater().

Referenced by main().

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

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