Exercise Wednesday

Goal: Focus on breaking your project down into small behavior examples and coding one behavior (also known as a "specification" or "spec") at a time. Make a list of specifications with input and output examples before writing any code. Also, as our projects grow in size, continue to practice good organization by keeping business logic and user interface logic distinctly separate.

Warm Up

Pretend you have an application that counts the number of vowels in a string. This application has specs detailing each behavior it must exhibit. However, they're out of order! Reorder the following list of specs from the simplest possible behavior to the most complex behavior with your partner. Consult with other pairs, if necessary:

  • The program recognizes vowels in a multiple-word sentence, regardless of capitalization.
    • Input Example: "CATS CATERED THE EVENT"
    • Output Example: 7
  • The program recognizes a single vowel in a multiple-character word.
    • Input Example: "cat"
    • Output Example: 1
  • The program recognizes a single vowel.
    • Input Example: "a"
    • Output Example: 1
  • The program recognizes multiple vowels in a single word.
    • Input Example: "cater"
    • Output Example: 2
  • The program recognizes a single vowel, regardless of case.
    • Input Example: "A"
    • Output Example: 1
  • The program recognizes all vowels in a multiple-word sentence, regardless of inconsistent capitalization.
    • Input Example: "CaTS CATEReD ThE EveNT"
    • Output Example: 7
  • The program ignores non-alphabetical characters, since they cannot be vowels.
    • Input Example: "4%"
    • Output Example: 0
  • The program recognizes vowels in a multiple-word sentence.
    • Input Example: "cats catered the event"
    • Output Example: 7


Leap Year

Follow along with the leap year lessons to build an application that identifies whether a given year is a leap year. Make each of the specs detailed in the leap year lessons "pass" (ie: your program returns the expected output for the expected input).

Specs from Leap Year Lessons

  • The program should return when a year is not a leap year.
    • Input Example: 1993
    • Output Example: false
  • The program should return 'true' for years divisible by 4, since those are leap years.
    • Input Example: 2004
    • Output Example: true
  • The program should return 'false' for years divisible by 100, since those are not leap years.
    • Input Example: 1900
    • Output Example: false
  • The program should return 'true' for years divisible by 400, since those are leap years.
    • Input Example: 2000
    • Output Example: true

All specs should be listed in the project's README.md file.

Pig Latin

Write a Pig Latin translator or should we say an "igPay atinLay anslatorTray"? Read all instructions carefully before beginning.

How Pig Latin Works

First, here are the rules of Pig Latin:

  • For words beginning with a vowel, add "way" to the end.

  • For words beginning with one or more consonants, move all of the first consecutive consonants to the end, and add "ay".

  • If the first consonants include "qu", move the "u" along with the "q". Don't forget about words like "squeal" where "qu" doesn't come first!

  • For words beginning with "y", treat "y" as a consonant.


  1. Before writing any code, make a list of specs detailing each behavior your program will have. Start with the simplest possible behavior, and slowly move up in complexity. To get you started, the first two specs are provided below.

  2. Have at least two other pairs check your specs before you begin coding. Ensure that each possible behavior is represented by a spec, and that they are ordered from simplest to most complex.

  3. Place your specs (and their example inputs and outputs) in your project's README.

  4. Create a basic user interface that allows your application to accept user input, and display output. This will allow us to manually test each spec.

  5. Slowly add business logic. Begin by focusing on the behavior outlined in your first, most simple spec. Implement the least amount of logic necessary to create this behavior.

  6. Manually test this behaviour by inputting the example input described by the spec into your application, and confirm you receive the correct output.

  7. Once behavior outlined by the first spec is successfully implemented, repeat steps 5 - 7 for each subsequent spec. Do not move onto the next spec until the previous one passes.

Helpful Hints

When you get to consonants, don't try to solve it all at once. Instead, start with an example of a word that only has one consonant; then a word with two consonants; then a word with three; and then tackle the exceptions to the rule, like "qu" and "y". Once your application can successfully translate single words, work on translating entire sentences.

Although you're welcome to solve the problem however you'd like, there are a few methods that would be handy:

Take a look at this and other documentation to gather the tools you'll need before you try to fulfill your specs.


To get you started, below are the first two "plain English" specs:

  • The program does nothing to non-alphabetical characters, since they do not contain consonants or vowels.
    • Example Input: 3
    • Example Output: 3
  • The program adds "ay" to single-letter words beginning with a vowel.
    • Example Input: i
    • Example Output: iay

Further Exploration

Refactor with Regular Expressions

Refactor your code for the projects above using regular expressions. A handy place to try using regular expressions before implementing them is at Rubular.


Binary: Write a method to convert numbers from binary to decimal. The input should be a string, and the output an integer. Decimal is the normal system we use for counting. We start at 0, increment until we reach 9, and then reset back to 0 and add another number to the left. In binary, we also start at zero, but we only increment until we reach 1. Then we reset back to zero and add another number to the left.

Here are some example of numbers in decimal and binary:

Decimal  Binary
  0        0
  1        1
  2       10
  3       11
  4      100
...      ...

Trinary: You get where I'm going, right?

Hexadecimal: Here's what happens after 9...

Decimal  Hexadecimal
...      ...
 9        9
10        a
11        b
12        c
13        d
14        e
15        f
16       10
17       11
...     ...

If you get this far, write a method that takes two arguments: the number to be evaluated and the base you would like it to be evaluated in.

Peer Code Review

  • Is code broken down into plain English specs?
  • Do these specs accurately represent the behaviors required of the program?
  • Are there any additional specs you can think of?
  • Is the business and user interface logic well-separated?
  • Does the application work as expected?

If you would like to view an example README, check out this one made by Epicodus graduates, David Wilson and Marilyn Carlin. Below is the raw version.

# Scrabble Score Checker

#### A program that allows users to input a word and determine its raw Scrabble score, assuming no special tiles. 6/1/17

#### By **Marilyn Carlin and David Wilson**

## Description

A website created with C# and HTML where a user can submit a word and determine its raw Scrabble score.

### Specs
| Spec | Input | Output |
| :-------------     | :------------- | :------------- |
| **Homepage** | User accesses localhost:5004 | Homepage with user input form |
| **Program Gathers User Input** | User input: "pants" | Output: "pants" |
| **Program Removes Spaces from User Input**| User Input: "pants pants" | Output: "pantspants" |
| **Program Removes Punctuation from User Input**| Input: "p#an^[email protected]  /p(ant%s" | Output: "pantspants" |
| **Program Assigns Characters Numeric Values** | Input: "pants" | Output: "3 1 1 1 1" |
| **Program Sums Character Values**| Input: "3 1 1 1 1" | Page Displays: 7 |

## Setup/Installation Requirements

1. To run this program, you must have a C# compiler. I use [Mono](http://www.mono-project.com).
2. Install the [Nancy](http://nancyfx.org/) framework to use the view engine. Follow the link for installation instructions.
3. Clone this repository.
4. Open the command line--I use PowerShell--and navigate into the repository. Use the command "dnx kestrel" to start the server.
5. On your browser, navigate to "localhost:5004" and enjoy!

## Known Bugs
* No known bugs at this time.

## Technologies Used
* C#
  * Nancy framework
  * Razor View Engine
  * ASP.NET Kestrel HTTP server
  * xUnit


## Support and contact details

_Email no one with any questions, comments, or concerns._

### License

*{This software is licensed under the MIT license}*

Copyright (c) 2017 **_{Marilyn Carlin, David Wilson}_**