Homework 3: The Haunted House

Due: Tuesday September 24, 2019 at 9:00PM EST.

enter image description here

Handin

After completing the homework, you will submit:

If you are using late days, make sure to make a note of that in your readme. Remember, you may only use a maximum of 3 late days per assignment. If the assignment is late (and you do NOT have anymore late days) no credit will be given.

Helpful Things

Documentation

Useful Functions

The Assignment

Coordinates

Velma and Detective Pikachu will need to investigate a haunted house as a part of the case they are trying to solve. In order to get to the haunted house, they need to use the Mystery Mobile! To navigate the Mystery Mobile, you need to enter its coordinates. However, if you don’t follow the Mystery Mobile’s rules about how to enter the coordinates, you will be unable to get to the haunted house!

The coordinate string must:

Fill in the function coordinate-check in the file coordinates.arr that takes in a coordinate String and returns true if the coordinates follow the rules, and false if they do not.

Examples:

In order to check if your function works or not, we encourage you to write tests. The tests provided are only a small subset of the full test suite. You should not assume your function works because is passes those test cases, as there are other cases that may have not been tested. Testing will assert that your function is returning the output you expect. These are examples of a test case:

coordinate-check("<abc,-12>") is false
coordinate-check("<dog,cat>") is true

Finally, format the function in such a way that follows the Design and Clarity Guide.

Hint: Take a look at this documentation and this documentation as you may find it useful.

Warning: Being able to look in language documentation for useful operations is an important skill, which is why we aren’t telling you exactly which string operations to use. We want you to look at the string documentation to find useful operations for solving this problem. However, limit yourself to operations with input and output types that we have used this semester (Number, String, Boolean). Don’t use operations that return List, as we haven’t covered that yet.

Inspecting the House

Is it safe? After arriving at the haunted house, you have to make sure that the conditions of the house are safe for you to enter and examine it.

Fill in the function called is-house-safe, which takes in:

The function should return “safe” if it is safe to enter the house to examine it, "warning" if we should be careful, and “dangerous!” if we should not enter.

It is safe to enter the haunted house if all of the following are true:

If only one of these conditions is false, the function should return "warning": meaning we can enter the house, but need to be cautious while examining the house. If more than one of the conditions is false, then we cannot enter, the risk is too high! Thus, the function should return "dangerous"!

Don’t forget to follow the design and clarity guidelines!

Hint: You will probably want to use an if expression to decide which String to return! Generally, if you only need to return a Boolean, you can use ands and ors to express your conditionals, but when you need to return something else you will need an if statement.

Ghost Detector

Before Velma and Detective Pikachu use the ghost detector tool (it’s very expensive to use), they asked Jennifer if she could lend them her price calculator for the ghost detector. Jennifer wrote some code to help her calculate the rates for each use, but unfortunately she has forgotten to follow the design and clarity guide! In order for Velma and Detective Pikachu to understand Jennifer’s code, you’ll need to help by cleaning up the code!

Jennifer wrote the function calculate-rate, which takes in the number of minutes that they use the ghost detector and returns the cost of the use.


fun calculate-rate(minutes):
  low-minutes-cost = 5
  medium-minutes-cost = 10
  high-minutes-cost = 15
  if ((minutes >= 0) and (minutes < 11)):
    (minutes / (low-minutes-cost / 12)) * (10 + (minutes * 3))
  else if ((minutes >= 11) and (minutes < 20)):
    (minutes / (medium-minutes-cost / 12)) * (10 + (minutes * 3))
  else if (minutes >= 20) :
    (minutes / (high-minutes-cost / 12)) * (10 + (minutes * 3))
  end
where:
  calculate-rate(12) is 662.4
end

Help Jennifer clean up her code by making the following improvements:

  1. Add type annotations,
  2. Add docstrings,
  3. Write more thorough test cases, and
  4. Clean up the code as you see fit. In particular, there are some instances of repetition!

README.txt

No additional responses required for this week! Still submit a README though (we use it to track late days and collaboration stuff)!

Brown University CSCI 0111 (Fall 2019)
Do you have feedback? Fill out this form.