Lab 3: Daily Gazette

In this hands-on activity we will be making a calculator to determine how much you owe the newspaper to place an ad, based on word count, taxes, coupons, specials, and so on.

Example

You know how groceries are cheaper when you buy them in bulk? What we're doing today is similar to that, but for buying ads in a newspaper: the more words in your ad, the more it's like buying groceries in bulk.

What we want is a program that will answer the question, "How much money do I owe the newspaper?"

For example, in JavaScript:

// Input Variables
var word_count = 80;
var tax_rate = 1.06;
var bulk_cutoff = 100;
var regular_price = 0.10;
var bulk_price = 0.08;

// Let's calculate the answer
var subtotal = 0;
if (word_count < bulk_cutoff){
    subtotal = word_count * regular_price;
}

if (word_count >= bulk_cutoff){
    subtotal = word_count * bulk_price;
}

var total = subtotal * tax_rate;

// Let's format the message
var message = "The total to place an ad of "+word_count+
              " words with a tax rate of "+tax_rate+
              " is "+total+
              " dollars.";

// And let's output the message and be done
console.log(message);

Questions

Part 1

  1. Answer for each language: What is the syntax for if statements in your language? How would you write an if statement that means "if your age is less than 18, then output no"? Demonstrate your answer with screenshots.
  2. What part of an if statement is called the "condition"?
  3. What are the "relational operators" and what does each mean?
  4. Answer for each language: Does your language use the = or == or === symbol to test equality between numbers? How would you write an if statement that means "if A is equal to B"? Demonstrate your answer with screenshots.
  5. What data type must the condition of an if statement always resolve to?

Part 2

  1. Pick one language from your group. What language did you choose for this task and why?
  2. In your chosen language, use RexTester to program the price calculator program described above. Change the value of the word_count variable to 120 and the tax_rate variable to 1.07. Demonstrate your answer with screenshots.

Part 3

For each of the following, demonstrate your answer with screenshots of the program you wrote above being used to answer the word problem:

  1. What is the price to run an ad with 101 words, a bulk cutoff of 90 words, a regular price of 0.15 per word, a bulk price of 0.10 per word, and a tax rate of 1.08?
  2. With the same settings as question 1 here, is it cheaper to run an ad of 89 words or 91 words?
  3. The magazine is running a special where you receive a seven percent discount if your ad has a multple of seven words. With the same values as question 1 here, how much would an ad with 111 words cost? 112 words? 113 words? (Hint: to apply a seven percent discount, multiply by 0.93)