This is a Ruby application that calculates the total price and sales tax for a list of purchased items based on predefined tax rules.
- Applies a 10% sales tax to non-exempt items.
- Applies a 5% import duty to imported goods.
- Rounds tax amounts to the nearest 0.05.
- Generates a receipt with itemized costs, total sales tax, and total price.
- Includes an interactive mode for user input.
- Contains RSpec tests to verify correctness.
Install RSpec for testing (if not already insta 6B3C lled):
gem install rspec
Run the script in the terminal:
ruby tax_calculator.rb
Enter your items in the following format:
<number> <item name> at <price>
Type done when finished. Example:
2 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85
done
The receipt will be displayed as output.
To run the RSpec tests:
rspec spec/tax_calculator_spec.rb
This will validate the implementation against sample inputs.
2 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85
done
2 book: 24.98
1 music CD: 16.49
1 chocolate bar: 0.85
Taxes: 1.50
Total: 42.32