Day 2: Basic File and Data Manipulation
Introduction
We will now put to use what we have learned so far. Before you attempt a problem, be sure to:
Read through the entire problem statement individually.
Check your understanding of the problem by discussing with your partner:
What the program needs to do.
How it can be implemented.
Write or type, in plain English, the instructions you and your partner want your program to follow.
For some problems you may need to google for information. Remember that as pairs, you are also googling together. Please switch driver and navigator for each problem statement.
When you run into a bug, talk out loud with your partner what you expected to happen, and what happened instead, before attempting to find a solution.
If needed, use the 'ask host for help' function in Zoom. You may also find the "annotate" feature in Zoom useful when pair programming.
Base
For each exercise, make a copy of the starter code as per the recommended folder structure for Fundamentals. For some exercises you may need to google for information.
See an example of all problems here.
Minutes in Weeks
The user will enter a number of weeks. The program should output the number of minutes in those weeks in the output box.
Format the output nicely. Like: In 3 weeks there are 30240 minutes! Wow!
Fahrenheit to Celsius
The user enters a temperature in Fahrenheit. The program should output the conversion to Celsius in the output box.
Format the output nicely.
Road Trip Cost
The user will enter the length of a planned road trip in his brand new Ferrari. The program should output the estimated fuel cost of the road trip.
A new Ferrari consumes 9km/litre. Petrol costs $2.20/litre.
Format the output nicely.
Ice Cream Buffet
There's all-you-can-eat ice cream at the buffet. The buffet receives ice cream in 400ml containers. To save money the buffet only provides 70ml cups for customers to get ice cream.
The user will enter a number of trips to the ice cream station (picking up 1 cup per trip) and the app will calculate how many containers of ice cream you would consume. It is ok to show the number of containers in decimal format.
Time to Type Sonnets
The user will enter their words-per-minute typing speed. The app will calculate how long it will take them to type all of Shakespeare's sonnets in hours.
For simplicity, assume 17,677 words in all of Shakespeare's sonnets.
Comfortable
See an example of all problems here.
Cost of Air Con
The user enters the number of hours of air-con use, and the app tells them the cost.
An aircon machine uses 2 kilowatts of electricity.
Electricity costs $0.20 per kilowatt-hour.
Screen Time
The user will enter the number of hours spent per day on their favourite app, and the program renders how many days you will spend in your lifetime on this app.
Assume an average life expectancy of 82 years.
On Android 10, iOS 12, and later versions, we can see how many hours per day we spend on each app. Find the number of hours you spend per day on the app you use most. If you're not able to find this, you can google for common statistics.
For example, if I spend 2 hours per day on WhatsApp and I live an average lifetime of 82 years, how many total days will I spend on WhatsApp during my life?
More Comfortable
Ice Machine
A hotel uses an ice machine to prepare ice for guests. They want to start the ice machine as close to each event as possible, so that the ice doesn't melt. In order to do this, they need to estimate how long they will need to run the ice machine.
Create a program that estimates the duration the ice machine needs to run. The user will input the number of guests for the event.
Assume each guest needs 2 drinks. Each drink has 4 ice cubes. Each cube weights 1.5 grams. The hotel's American-made ice machine produces 5 pounds of ice per hour.
Beer Order
Create a program for a bar to calculate how many kegs of beer they will need every day. The user will enter the average number of customers per day, and the app will estimate how many half-barrel-size kegs the bar needs per quarter.
Assume an average customer drinks 2 pints per visit. There are 124 pints of beer in a half-barrel keg.
Reference Solution
Here is a reference solution for the Data Manipulation exercises above. Please only view the reference solution for each exercise after you have attempted the exercise yourself. Note that there are many ways to implement these solutions and the reference solution is only 1 way.
Last updated