Calculate Sales Tax
Learn about modules and mixin in Ruby.
Problem
The sales tax in Australia is called the goods and services tax (GST) of 10%, which is applied to most products and services. For example, in a physio clinic, medical services such as physiotherapy are GST-free. However, GST applies to pilates classes (also a service), and also to all products sold at the clinic. All businesses must show GST-inclusive prices. For example, for a $10 meal, $9.09 is the net amount and $0.91 is sales tax.
Write a program below that defines the Goods
and ServiceItem
classes. Ensure that objects of both types can invoke the methods, net_amount
and gst
, to calculate the net amount and sales tax of products and services.
Expected Output
We can test the class definitions you provide with code as shown below:
foam_roller = Goods.new("Foam Roller", 49.95)physio_service = ServiceItem.new("Physio Consultation", 120.0)pilates_class = ServiceItem.new("Pilates Classes", 80.0)pilates_class.sales_tax_applicable = true
The values to be returned by invoking the ...