Q:

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

0

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. Overwrite the 

set.propertyname function to check that each property is the correct 

class and that:

 The employee ID has 10 digits

 The department is one of the following codes: HR (Human 

Resources), IT (Information Technology), MK (Marketing), AC 

(Accounting), or RD (research and Development)

 The rating is a number from 0 to 5. 

The rating should not be accessible to anyone without a password. 

Overwrite the set.rating and get.rating functions to prompt the user for

a password. Then, write a function that returns the rating.

All Answers

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

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now