2) Answer following questions based on the UML of the Employee class diagram sho
ID: 3877082 • Letter: 2
Question
2) Answer following questions based on the UML of the Employee class diagram shown below.
+ name : String
- idNumber : int
+ Employee(String, int, String)
+ String getName()
+ void setPositionTitle(String)
a) What is the class name?
b) How many public methods does this class have?
c) How many public data members does this class have?
d) Implement the Employee(String , int , String ) constructor above (No need to write the
complete program, only the constructor method.
e) Implement the setPositionTitle ( ) method. This method should return the position title
of the employee.
EmployeeExplanation / Answer
Note:I observed some mistakes in the questions.
1.Didnt mentioned the positionTitle in the UML diagram.
2.In UML diagram given the method declaration as void setPositionTitle(String) .means this method will not return anything.But why In Question 'e' mentioned that this method should return positionTitle.
Actually setter method will not return anything.This is used to set the value of the instance variable .positionTitle.
_______________
a) What is the class name?
Ans)Employee
____________
b) How many public methods does this class have?
Ans)3 (Constructor is also a method )
_______________
c) How many public data members does this class have?
Ans)1 (‘+’ sign represents public visibility)
____________________
d) Implement the Employee(String , int , String ) constructor above (No need to write the complete program, only the constructor method.
Ans)
Employee(String name,int id,String positionTitle)
{
this.name=name;
this. idNumber=id;
this. positionTitle= positionTitle;
}
____________
e) Implement the setPositionTitle ( ) method. This method should return the position title of the employee.
Ans)
void setPositionTitle (String positionTitle)
{
this. positionTitle= positionTitle;
}
________________ Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.