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

Roman Numerals

Write a method to convert numbers into Roman numerals. Roman numerals are based on seven symbols:

Symbol  Value
I       1
V       5
X       10
L       50
C       100
D       500
M       1,000

The most basic rule is that you add the value of all the symbols: so II is 2, LXVI is 66, etc.

The exception is that there may not be more than three of the same characters in a row. Instead, you switch to subtraction. So instead of writing IIII for 4, you write IV (for 5 minus 1); and instead of writing LXXXX for 90, you write XC.

You also have to separate ones, tens, hundreds, and thousands. In other words, 99 is XCIX, not IC. You cannot count higher than 3,999 in Roman numerals.

Draft some specifications and input-output examples to brainstorm the behaviors that you'll want to capture in your application. Tackle them one-by-one, worrying only about the future behaviors once the current example is implemented. All specifications should be listed in the project's README.md file. Do not move on to the next exercise until you've had a teacher review your code and specs.


A classic method for composing secret messages is called a square code.

The spaces and punctuation are removed from the English text and the characters are written into a square (or rectangle) and the entire message is downcased. For example, the sentence "don't compare yourself to others, compare yourself to the person you were yesterday" is 69 characters long, so it is written into a rectangle with 9 rows and 8 columns.

Cryptosquare image

The coded message is obtained by reading down the columns going left to right, outputting encoded text in groups of five letters. For example, the message above is coded as:

"daeer leweo rlref rerne fsyts rdtyt coooe acooo utnyy ouomr hyemr tpseo spsha eput"

Write a program that outputs the encoded version of a given block of text. Again, identify each individual behavior this application should demonstrate, and write a specification (including an input/output example) for each. Tackle writing code for one behavior at a time, and ensure your spec "passes" (you receive the correct output when you provide your input example) before moving to the next specification. List all specifications in the project's README.md file.

The size of the square (number of columns) should be decided by the length of the message. If the message is a length that creates a perfect square (e.g. 4, 9, 16, 25, 36, etc), use that number of columns. If the message doesn't fit neatly into a square, choose the number of columns that corresponds to the smallest square that is larger than the number of characters in the message.

encrypt("Have a nice day. Feed the dog & chill out!");
# => "hifei acedl v..."

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}_**