Comp 101 A Meal Without a Plan

A Meal Without a Plan


Part 1: Setting up the environment.

As with in lecture, begin by opening up VSCode, ensuring your project is still open, and then running the following two commands in the VSCode Integrated Terminal:

  1. npm run pull
  2. npm start

The first command "pulls" the latest files needed for COMP101 into your repo, if any. The second command starts the development environment and will open your web browser to the local server.

In the same directory used in lecture:

  1. Right click on the "src" folder
  2. Select "New Folder"
  3. Name the new folder: ps02-meal-plans
    1. Note: capitalization and punctuation are important!


Part 2.0 (a): Getting started.

  1. Right click on the ps02-meal-plans folder you just created
  2. Select "New File"
  3. Name the new file: 01-meal-plan-calculator-app.ts
    1. Note: capitalization and punctuation are important!


Part 2.0 (b): Honor Code Header

All problem sets begin with an Honor Code pledge. Notice this header is contained within block comment tags discussed in Lecture 1. You can copy paste the pledge below and fill in your name and ONYEN.

/**
 * Author:
 *
 * ONYEN:
 *
 * UNC Honor Pledge: I certify that no unauthorized assistance has been received
 * or given in the completion of this work. I certify that I understand and
 * could now rewrite on my own, without assistance from course staff, 
 * the problem set code I am submitting.
 */

Part 2.0 (c): Import statements.

The next step after ensuring the Honor Code header is importing the functions we'll use from the introcs library (i.e. printimage, and so on). Copy and paste the following line of code at the top of 01-meal-plan-calculator-app.ts (after the honor code statement):

import { print, promptNumber } from "introcs";

This imports the print and promptNumber functions so that we’ll be able to ask users for number input and display some values at the end of this part of the problem set.

Part 2.0 (d) The main Function

Your program's logic will begin a function named `main` just like in your first problem set. All of your code from this point on will go inside its brackets. Here is the incantation to setup your main function:

export let main = async () => {
   // TODO: Your code goes inside of this block.
};
main();


Part 2.1: Create variables to store the prices for different meals.

The goal of this assignment is to calculate the price per meal at the dining hall when you pay the full price for each meal instead of buying a dining plan. This will allow you to determine if you are better off buying a meal plan or purchasing each meal individually! The first thing we need to do is store the price that is charged for each meal if you were to use just pay with a credit card.

Here are the prices of each meal (tax included):

         Breakfast: $8.75

         Lunch: $11.50

         Dinner: $11.75

         Late Night: $9.75

What you need to do: Declare four number variables named breakfastPrice, lunchPrice, dinnerPrice, and lateNightPrice. Then, assign to these variables the values that correspond to the price of that meal (so that breakfastPrice will contain the value 8.75 and so on).

Part 2.2: Prompt the user for the number of different meals they will partake in during the semester, and store these numbers in variables.

Now that we have the prices for each meal stored, we need to ask the user how many of each type of meal they expect to eat in a semester.

Recall that this how we prompt a user for number input:

 let variableName: number = await promptNumber("What’s your number?");

What you need to do: Declare four number variables named numberBreakfasts, numberLunches, numberDinners, and numberLateNights. Then, assign the corresponding number values (provided by the user) to these variables. For example, you should assign numberBreakfasts the value of:

await promptNumber("How many breakfasts will you swipe in for this semester?");

Similarly, you should prompt the user for the number of lunches, dinners, and late nights they expect to each and store these values in numberLunches, numberDinners, and numberLateNights.

To help come up with realistic meal counts to respond to your prompts on your webpage, remember there are about 16 weeks in the semester on campus. Maybe, you expect to eat lunch and dinner every weekday at the dining hall but never eat breakfast or late night at the dining hall. You might choose to have 80 lunches (5 * 16), 80 dinners, 0 breakfasts, and 0 late nights. We will call this the 80-80-0-0 plan.

Part 2.3 (a): Create a variable to hold the total cost of all meals.

Now that you have the cost of each meal and number of each meal stored, we can calculate the total cost of your self-designed meal plan.

What you need to do: Declare a number variable called totalCost, and assign it the value of the sum of each meal’s price variable times that meal’s number variable. For example, the equation to calculate the total cost of our 80-80-0-0 meal plan would be 8.75 * 0 + 11.50 * 80 + 11.75 * 80 + 9.75 * 0. Your equation should look very similar, but it should use the variables (such as breakfastPrice and numberBreakfasts) in place of actual values.

Part 2.3 (b): Create a variable to hold the total number of meals.

Now we need to create a variable to hold the total number of meals.

What you need to do: Declare a variable called numberOfMeals, and assign it the value of the sum of the four number variables we prompted for in part 2.2.

Part 2.3 (c): Create a variable to hold the cost per meal, and print this value.

Finally, we will calculate the cost per meal!

What you need to do: Declare a variable named costPerMeal, and assign it the value of your totalCost variable divided by your numberOfMeals variable. Print this costPerMeal.

Congrats! You have completed this assignment. As a thought experiment, consider the block meal plan prices and corresponding price per meals below. Based off of your results from using your meal plan calculator, would you be better off without a meal plan next semester and instead just buying the meals a la carte?


Block 120: $1422 / 120 meals = $11.85 per meal

Block 160: $1788.80 / 160 meals = $11.18 per meal

Block 200: $2022 / 200 meals = $10.11 per meal

Part 2.4: Publish your block plan price per meal calculator.

With your program running in your web browser, find the green "Publish App" button. If you are not still logged into introcs.com, you will be prompted to log in, and then your app will be bundled and published to the web!

Part 2.5:. Submit for grading

To submit for grading first publish your project. Then, go to My101 in the top-right right corner of this page and select "Submit" next to the assignment. From here you should see a button that allows you to submit for grading. Your work will be graded through an automated process. If you receive points off, please select the "Report" link to see which tests did not pass. You can resubmit as many times as you'd like without penalty up until the deadline. We want you to keep working toward full credit on problem sets