Create a class that stores information on a company’s employees. The class will have properties to store the employee’s name, a 10-digit ID, their department and a rating from 0 to 5
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:11| Question number:15.11
All Answers
total answers (1)
classdef employeeData
properties (SetAccess = protected)
name
id
depart
end
properties (Access = private)
rating
end
methods
function obj = employeeData(varargin)
if nargin == 1
obj.name = varargin{1};
elseif nargin == 2
obj.name = varargin{1};
obj.id = varargin{2};
elseif nargin ==3
obj.name = varargin{1};
obj.id = varargin{2};
obj.depart = varargin{3};
elseif nargin ==4
obj.name = varargin{1};
obj.id = varargin{2};
obj.depart = varargin{3};
obj.rating = varargin{4};
else
error('Invalid number of inputs')
end
end
function obj = set.name(obj,val)
if isa(val,'char')
obj.name = val;
else
error('Not a valid name')
end
end
function obj = set.id(obj,val)
if isa(val,'double')&&numel(num2str(val)) == 10
obj.id = num2str(val);
else
error('Not a valid ID number')
end
end
function obj = set.depart(obj, val)
if strcmp(val,'HR')
obj.depart = val;
elseif strcmp(val,'IT')
obj.depart = val;
elseif strcmp(val,'RD')
obj.depart = val;
elseif strcmp(val,'AC')
obj.depart = val;
elseif strcmp(val,'MK')
obj.depart = val;
else
error('Not a valid department')
end
end
function obj = set.rating(obj,val)
code = input('Password Required:');
if code == 1234
if isa(val,'double') && val>=0 && val<=5
obj.rating = val;
else
error('Invalid rating input')
end
else
error('Invalid Password')
end
end
function val = get.rating(obj)
code = input('Password Required:');
if code == 1234
val = obj.rating;
else
error('Invalid Password')
end
end
function rat = seeRating(obj)
rat = obj.rating;
end
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer