🚀 Basics Day 1: In-Class Exercises 🚀

Pre-Class In-Class

Base: Fahrenheit to Celsius

The user enters a temperature in Fahrenheit. The program should output the conversion to Celsius in the output box.

Write the code inside the main function first, then extract the code into a helper function that accepts Fahrenheit as the input and outputs Celcius.

The formula for Fahrenheit to Celcius: Celcius = (Fahrenheit-32) x 5/9


Temperature in Fahrenheit:


Output:

Base: Road Trip Cost

The user will enter the length (in km) of a planned road trip in his brand new Ferrari. Write a program that outputs the total fuel cost (in $) of the road trip.

A new Ferrari is able to travel 9 miles/litre of fuel. Fuel costs $2.20/litre.


Enter the length (in km) of a planned road trip:


Output:

Comfortable: Road Trip Cost

The user enjoyed his road trip so much that he decided to do another road trip again but he wishes to compare the cost of travelling via train against the cost of travelling via his Ferrari.

The user will enter the length (in km) of the road trip. Write a program that outputs the savings in fuel cost (in $) of the road trip if he were to travel via train compared to using his Ferrari.

The Ferrari and train are both able to travel 9 miles/litre of fuel. Fuel for the Ferrari costs $2.20/litre. Fuel for the train costs $2.00/litre.


Enter the length (in km) of the road trip:


Output:

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.


How many guests are you expecting for the event?


Output:

More Comfortable: 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.


What is the average number of customers per day?


Output:

More Comfortable: Cost of Cellular Data

Create a program to calculate how much a user will pay for their the $19.99 50GB post-paid data plan. The user will enter how many GB they use per month, and the app will tell them how much they are paying per GB of data used.

Assume that if the user exceeds 50GB, they will automatically purchase an additional 50GB plan. You may find the built-in function Math.ceil helpful for this (you can Google how to use it).

For example, if the user only used 1GB this month, the app would calculate $19.99 per GB as the user paid $19.99 for the 50GB plan but only used 1GB. If the user used 2GB this month, the app would calculate $9.98 per GB. If the user used 51GB this month the user would have automatically been billed for 2 plans and the app would calculate $0.78 per GB.


How much cellular data (in GB) do you use per month?


Output: