Exercise Monday

Goal: Continue practicing both foundational C# concepts, and test-driven development as you tackle increasingly complex programs and challenges!

Warm Up


  • What kind of objects can be stored in other objects? Where have we seen this concept before?
  • When is the appropriate time to use a try/catch block? What benefit do they offer?
  • What does it mean when we state that a program "threw an exception"? What occurs when this happens?
  • In terms of Test-Driven Development, what does "arrange, act, assert" mean? What does it look like to follow this process?
  • Compare the tests you wrote for your last project with your partner, and give each other feedback; do tests begin with the simplest possible behaviors and move up in complexity? Does it look like each of you followed the "red-green-refactor" process? If not, how can you write better tests today?
  • What is abstraction and how can we use this principle to improve our code?

Code


Scrabble Score

Make a console application that takes a word and returns the Scrabble score for that word. Make sure to start with your specs, and that you include a README for this project and create a Git repository for it. Here are the values of letters in Scrabble:

A, E, I, O, U, L, N, R, S, T       1
D, G                               2
B, C, M, P                         3
F, H, V, W, Y                      4
K                                  5
J, X                               8
Q, Z                               10

Numbers to Words

Create a console app that translates numbers in numeric form into written words. For example, it would translate 384 into "three hundred eighty four". Use multiple dictionaries to solve this.

Start small, and then get your code working for numbers up to 1 trillion.

Need I remind you to start with your specs and use TDD as you go? Make sure you include a README for this project and create a Git repository for it.

If you get this far, you've done great! Don't worry about getting to the rest of the projects by the end of the day.

Find and Replace

Create a console app where a user enters a string, chooses a word in that string and provides a replacement for that word. Your method in action could look something like FindAndReplace("Hello world", "world", "universe"). The result of which would be "Hello universe".

Do first: Write the method so that it replaces whole words only, as in the "hello world" example above. First, write your specs in english with an input/output example for each one. Then, one by one, create test methods for your english specs and make them pass.

Do second: Add to your method, so that your method takes into account partial matches. For example FindAndReplace("I am walking my cat to the cathedral", "cat", "dog") would return the silly phrase "I am walking my dog to the doghedral."

Make sure to account for odd user inputs like all capitalization, partial capitalization, etc. Make sure you include a README for this project and create a Git repository for it.

Peer Code Review


  • Did you include English specs as a separate text file (or README)? Was it committed before you began your code?
  • Do your specs include specific input and output as well as a descriptive sentence?
  • Do your specs start with the simplest case and progress to more complex cases? Do they cover enough different input values?
  • Have all specs been written up correctly as test methods?
  • Are all tests passing?

Lesson 8 of 12
Last updated more than 3 months ago.