HW#22 College Cost Calculation App
More practice of IBAction, IBOutlet, Optional, & Keypad
Although the arithmetics in this App is relatively simple, it is fun going through what we have covered in class. In this homework, I chose to make a college cost calculation app.
Yep, it is getting more and more costly studying abroad, especially if one wants to enter those prestigious and top-notch universities.
Here are the links I have checked in order to make this app:
Let’s take a look at the code I wrote:
My calculation is simple, just add all the items of cost to get the total cost for studying at a university for one year. Then divide the total cost with 12 to get the cost per month.
Notice that : I wrote “%.1f” to calculate the number to the first decimal place.
// calculate the total cost
let totalCost = tuition + livingCost + insurance + housing + books totalCostLabel.text = String(format: “%.1f”, totalCost) + “ USD”
// calculate per month cost let perMonthCost = totalCost / 12 perMonthCostLabel.text = String(format: “%.1f”, perMonthCost) + “ USD”
Let’s take a look at the interface of the app.
Because I wanted to practice using SpriteKit again, so I added the snow particle effect. This time I changed the symbol to the money sign. At the beginning I forgot to add “Import SpriteKit” in the code, so the effect couldn’t come out. Luckily, I found that out right away.
Another issue I figured out how to solve is that if you cannot see the keypad jump out, you can go to Simulator →I/0 →Keyboard → click Connect Hardware Keyboard. Then the keypad should appear.
Finally, here is the gif of the app. Happy Coding!