Time for action – Managing a fridge
We are going to create software to manage a fridge. We want to be able to add meals inside it, and to list what is in it. Ok, let's start!
Create a folder that is going to hold your project's files.
Create two folders inside it: a
src
folder and abin
folder.In your
src
folder, create aMyFridge
folder. This way, we now have aMyFridge
package.In the
MyFridge
package, create aFridge.hx
file with the following code inside it:package MyFridge; class Fridge { public static var meals = new List<Meals>(); }
This way, our fridge will hold a list of meals inside it. We can make this variable static because we will only have one fridge.
Now, in the
MyFridge
package, create a file namedMeal.hx
and write the following code in it:package MyFridge; class Meal { public var name : String; public function new(f_name : String) { this.name = f_name; } }
We now have a class
Meal
and its instances will have a name.We will now create a menu....