January 22 - Build a Tip Calculator in Ruby that Can Accept Multiple Data Types as Input
In this coding exercise we'll build out an extensive tip calculator that can accept integers, string based numbers and even words to dynamically generate a tip.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Build a Ruby module that can accurately process tip amounts based on input with multiple data type options.
Exercise File
Exercise Description
The key to this exercise is understanding how to properly manage multiple data type inputs and then to process the tip calculations.
Example Behavior
Tippy::Builder.new(total: 100, gratuity: '23.5').generate # 123.5 Tippy::Builder.new(total: 100, gratuity: 'high').generate # 125.0 Tippy::Builder.new(total: 100, gratuity: 'LOW').generate # 115.0 Tippy::Builder.new(total: 100, gratuity: 'standard').generate # 118.0 Tippy::Builder.new(total: 100, gratuity: '18').generate # 118.0 Tippy::Builder.new(total: 100, gratuity: 20).generate # 120.0 Tippy::Builder.new(total: 100, gratuity: 0).generate # 100.0
Please note that you need to handle:
- Parsing string based numbers such as
'20'
- Traditional integers
- Words, such as
high
,standard
, andlow
. You can look at the tests to figure out what percentages those words should represent.
Real World Usage
This is going to be a challenging exercise that will test a number of coding techniques, such as:
- Working with modules and classes
- Performing metaprogramming
- Control flow for varying data types
- Regular expressions
Each of these components are utilized in day to day development.
Solution
Can be found on the solutions branch on github.