Lesson 8. Capstone 1

 

This lesson is slightly different from what we’ve covered so far. Instead of learning a new language feature, you’ll try to solve a larger exercise that’s designed to bring together all the lessons covered to this point in the book. In this lesson you’ll be expected to

  • Make changes to an existing F# application in Visual Studio
  • Use the REPL as a development playground to help you develop solutions
  • Port code from scripts into an F# application that’s compiled into an assembly
  • Write code by using expressions and immutable data structures

8.1. Defining the problem

For this exercise, you’re going to work on a code base that builds on the petrol car example from earlier in this unit. The objective is to write a simple application that can drive the car to various destinations without running out of petrol. A basic application structure has already been written for you for the console runner, but the implementation of the core code needs to be done:

1.  Your car starts with 100 units of petrol.

2.  The user can drive to one of four destinations. Each destination will consume a different amount of petrol:

  1. Home—25 units
  2. Office—50 units
  3. Stadium—25 units
  4. Gas station—10 units

5.  If the user tries to drive anywhere else, the system will reject the request.

6.  If the user tries to drive somewhere and doesn’t have enough petrol, the system will reject the request.

7.  When the user travels to the gas station, the amount of petrol in the car should increase by 50 units.

8.2. Some advice before you start

8.3. Starting small

8.4. Implementing core logic

8.5. Testing in scripts

8.6. Moving to a full application

Summary