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
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:6.11
All Answers
total answers (1)
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