Q:

Create a class that will store the price of an item in a store, as well as the sales tax rate. Write an ordinary method to calculate the total price of the item, including the tax

0

Create a class that will store the price of an item in a store, as well as the sales tax rate. Write an ordinary method to calculate the total price of the item, including the tax.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

classTax.m

classdef classTax

 properties

 price

 rate = 6.25

 end

 

 methods

 

 function obj = classTax(varargin)

 if nargin == 0

 obj.price = 100;

 elseif nargin == 1

 obj.price = varargin{1};

 else

 obj.price = varargin{1};

 obj.rate = varargin{2};

 end

 end

 

 function tot = total(obj)

 tot = obj.price + obj.price * obj.rate/100;

 end

 end

end

>> amount = classTax

amount = 

 classTax with properties:

 price: 100

 rate: 6.2500

>> purchase = classTax(9.99)

purchase = 

 classTax with properties:

 price: 9.9900

 rate: 6.2500

>> bought = classTax(1000, 5)

bought = 

 classTax with properties:

 price: 1000

 rate: 5

>> purchase.total

ans =

 10.6144

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now