Today we will be learning about data types, arithmetic, and variables while using the Car Factory project we started last time. So let's get started!
Open up you Car Factory project. Navigate to the Minivan.h file. Here we will create some properties. Now
Data Types, Arithmetic, and Variables
- int - short for integer. It is a data type that holds an integer. (10, 30, 45)
- float - short for floating point numbers. It is a data type that holds decimals. (3.23, 2.65)
- char - short for single character. It is a data type that holds a single letter. ('P', 'K', 'b')
- double - same as float. It is a data type that stores floating point numbers, but it has twice the range as float. (9.53e + 13)
- id - stores any type of object. I don't recommend using it. Only use when you don't know what the type of the object will be.
Now go to you Minivan.m file. Go to your init method. Here is how you declare and implement these data types.
In you init method declare an int called gas and set its value to 0. Here is how the final init method should like.
Now go to ViewController.m At the top you need to import the Minivan header file so you have access to Minivan's properties and methods. Then create an object of type Minivan and call the
fillGasWithThisManyGallons:(int)gallons method from there.
Wow! That was a lot of material we covered in the last two tutorials! Take a break. Sometimes the best way to really understand the material is just taking a step back to really think about what you read. Be prepared though because in the next set of posts, we will be covering loops and making decisions in code.
Thank you,
Zachary Cmiel
The PoKoBros