From 9528d25d7b90456b376783512a36e47a96072aea Mon Sep 17 00:00:00 2001 From: Ricardo Alonso Date: Mon, 30 Nov 2020 13:28:53 +0100 Subject: [PATCH 1/2] Create index.php challenge is ok --- index.php | 347 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 347 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..c185ff4 --- /dev/null +++ b/index.php @@ -0,0 +1,347 @@ + + +$Euros >= $ingredient) + { + $this->$Euros -= $ingredient; + + array_push(self::$result, "Your product is here."); + array_push(self::$result, "Your change:"); + + $this->getChange(); + + $this->$Euros = 0; + } + else + { + array_push(self::$result, "Sorry, but you haven't entered enough coins"); + } + } + + private function getChange() + { + $resultCoins = strval($this->$Euros / 1); + if (intval($resultCoins) > 0) + { + array_push(self::$result, intval($resultCoins) . ' X ' .number_format(1, 2, ".", ",")); + $this->$Euros -= (intval($resultCoins) * 1); + } + $resultCoins = strval($this->$Euros / 0.25); + if (intval($resultCoins) > 0) + { + array_push(self::$result, intval($resultCoins) . ' X ' .number_format(0.25, 2, ".", ",")); + $this->$Euros -= (intval($resultCoins) * 0.25); + } + $resultCoins = strval($this->$Euros / 0.1); + if (intval($resultCoins) > 0) + { + array_push(self::$result, intval($resultCoins) . ' X ' .number_format(0.10, 2, ".", ",")); + $this->$Euros -= (intval($resultCoins) * 0.1); + } + $resultCoins = strval($this->$Euros / 0.05); + if (intval($resultCoins) > 0) + { + array_push(self::$result, intval($resultCoins) . ' X ' .number_format(0.05, 2, ".", ",")); + $this->$Euros -= (intval($resultCoins) * 0.05); + } + } + + // Public functions + public function getCoins($euros) + { + $this->$Euros += $euros; + } + + public function setCoins() + { + return $this->$Euros; + } + + public function getReturnCoins() + { + self::$returnCoins = true; + self::$returnMoney = $this->$Euros; + $this->$Euros = 0; + } + + public function returnCoins() + { + if (self::$returnCoins) + { + if (self::$returnMoney != 0) + { + $this->$Euros = self::$returnMoney; + + array_push(self::$result, "Your change:"); + + $this->getChange(); + + $this->$Euros = 0; + } + else + { + array_push(self::$result, "Sorry, but you haven't entered enough coins"); + } + + self::$returnCoins = false; + } + + if (!empty(self::$result)) + { + return self::$result; + } + + return null; + } + + public function getWater() + { + $this->getIngredient(self::Water); + } + + public function getJuice() + { + $this->getIngredient(self::Juice); + } + + public function getSoda() + { + $this->getIngredient(self::Soda); + } + } + +?> + +getCoins($_POST['euros']); + + $_POST['euros'] = null; + $_SERVER["REQUEST_METHOD"] = ""; + } + + if (isset($_POST['Water'])) + { + $objVending->getWater(); + } + + if (isset($_POST['Juice'])) + { + $objVending->getJuice(); + } + + if (isset($_POST['Soda'])) + { + $objVending->getSoda(); + } + + if (isset($_POST['ReturnCoins'])) + { + $objVending->getReturnCoins(); + } + } + + $_SESSION['objVending'] = $objVending; +?> + + + + + + + + + + + Vending Machine + + + + + +
+
+
+

Vending Machine

+

This is a challenge for a simple Vending Machine.

+
+
+
+ +
+
+

Insert Coin

+
+
+ 0.05 + 0.10 + 0.25 + 1.00 +
+
+

+
+
+
+
+

Total

+
+
+ +
+ +
+
+
+
+

+
+
+

Water

+ + + + +

+

0.65

+

+

+

+ +
+

+
+
+

Juice

+ + + +

+

1.00

+

+

+

+ +
+

+
+
+

Soda

+ + + + +

+

1.50

+

+

+

+ +
+

+
+
+
+ +
+

+
    + returnCoins() != null) + { + $arrayResult = $objVending->returnCoins(); + for($i=0;$i +
  • + + + +
+
+
+
+
+
+ + + + + + + + \ No newline at end of file From edec098543e2b92f3e17f9189c3490b2a33d3de4 Mon Sep 17 00:00:00 2001 From: Ricardo Alonso Date: Mon, 30 Nov 2020 13:32:55 +0100 Subject: [PATCH 2/2] Revert "Create index.php" This reverts commit 9528d25d7b90456b376783512a36e47a96072aea. --- index.php | 347 ------------------------------------------------------ 1 file changed, 347 deletions(-) delete mode 100644 index.php diff --git a/index.php b/index.php deleted file mode 100644 index c185ff4..0000000 --- a/index.php +++ /dev/null @@ -1,347 +0,0 @@ - - -$Euros >= $ingredient) - { - $this->$Euros -= $ingredient; - - array_push(self::$result, "Your product is here."); - array_push(self::$result, "Your change:"); - - $this->getChange(); - - $this->$Euros = 0; - } - else - { - array_push(self::$result, "Sorry, but you haven't entered enough coins"); - } - } - - private function getChange() - { - $resultCoins = strval($this->$Euros / 1); - if (intval($resultCoins) > 0) - { - array_push(self::$result, intval($resultCoins) . ' X ' .number_format(1, 2, ".", ",")); - $this->$Euros -= (intval($resultCoins) * 1); - } - $resultCoins = strval($this->$Euros / 0.25); - if (intval($resultCoins) > 0) - { - array_push(self::$result, intval($resultCoins) . ' X ' .number_format(0.25, 2, ".", ",")); - $this->$Euros -= (intval($resultCoins) * 0.25); - } - $resultCoins = strval($this->$Euros / 0.1); - if (intval($resultCoins) > 0) - { - array_push(self::$result, intval($resultCoins) . ' X ' .number_format(0.10, 2, ".", ",")); - $this->$Euros -= (intval($resultCoins) * 0.1); - } - $resultCoins = strval($this->$Euros / 0.05); - if (intval($resultCoins) > 0) - { - array_push(self::$result, intval($resultCoins) . ' X ' .number_format(0.05, 2, ".", ",")); - $this->$Euros -= (intval($resultCoins) * 0.05); - } - } - - // Public functions - public function getCoins($euros) - { - $this->$Euros += $euros; - } - - public function setCoins() - { - return $this->$Euros; - } - - public function getReturnCoins() - { - self::$returnCoins = true; - self::$returnMoney = $this->$Euros; - $this->$Euros = 0; - } - - public function returnCoins() - { - if (self::$returnCoins) - { - if (self::$returnMoney != 0) - { - $this->$Euros = self::$returnMoney; - - array_push(self::$result, "Your change:"); - - $this->getChange(); - - $this->$Euros = 0; - } - else - { - array_push(self::$result, "Sorry, but you haven't entered enough coins"); - } - - self::$returnCoins = false; - } - - if (!empty(self::$result)) - { - return self::$result; - } - - return null; - } - - public function getWater() - { - $this->getIngredient(self::Water); - } - - public function getJuice() - { - $this->getIngredient(self::Juice); - } - - public function getSoda() - { - $this->getIngredient(self::Soda); - } - } - -?> - -getCoins($_POST['euros']); - - $_POST['euros'] = null; - $_SERVER["REQUEST_METHOD"] = ""; - } - - if (isset($_POST['Water'])) - { - $objVending->getWater(); - } - - if (isset($_POST['Juice'])) - { - $objVending->getJuice(); - } - - if (isset($_POST['Soda'])) - { - $objVending->getSoda(); - } - - if (isset($_POST['ReturnCoins'])) - { - $objVending->getReturnCoins(); - } - } - - $_SESSION['objVending'] = $objVending; -?> - - - - - - - - - - - Vending Machine - - - - - -
-
-
-

Vending Machine

-

This is a challenge for a simple Vending Machine.

-
-
-
- -
-
-

Insert Coin

-
-
- 0.05 - 0.10 - 0.25 - 1.00 -
-
-

-
-
-
-
-

Total

-
-
- -
- -
-
-
-
-

-
-
-

Water

- - - - -

-

0.65

-

-

-

- -
-

-
-
-

Juice

- - - -

-

1.00

-

-

-

- -
-

-
-
-

Soda

- - - - -

-

1.50

-

-

-

- -
-

-
-
-
- -
-

-
    - returnCoins() != null) - { - $arrayResult = $objVending->returnCoins(); - for($i=0;$i -
  • - - - -
-
-
-
-
-
- -
-

© ralonsop 2020

-
- - - - - - \ No newline at end of file