Facebook
From anonOmuS, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 102
  1. BAHRIA UNIVERSITY (Karachi Campus)
  2. Department of Computer Science
  3. Mid Term Examination – Spring 2020
  4. OBJECT-ORIENTED PROGRAMMING (CSC-210)
  5. (TAKE HOME ASSIGNMENT)
  6. Class : BSCS 2nd Semester (A/B) (Morning)
  7. Course Instructor(s) : Sameena Javaid Submission Deadline: 31st May 2020
  8. Marks : 20
  9. Student’s Name: ________________________________ Reg. # : ______________
  10.  
  11. QUESTION NO. 1 (Inheritance - Case Study) (10 Marks)
  12. Maintain an employee management system for a company. The following UML diagram shows the
  13. relationship between the classes.
  14. Employee
  15. - Name:String
  16. - Id :int
  17. - Qualifiction:String
  18. + Employee( )
  19. + setName( String n): void
  20. + getName( ): String
  21. + setId( int i): void
  22. + getId( ): Int
  23. + setQualification(String q): void
  24. + getQualification( ): String
  25. + DisplayInfo( ) : void
  26. + getData( ):void
  27. MonthlySalEmployee
  28. - Basicpay : double
  29. - Allowances : double
  30. + getData ( ): void
  31. + setBasicpay( double bp): void
  32. + getBasicpay( ):double
  33. + setAllowances( double al): void
  34. + getAllowances( ): double
  35. + DisplayInfo( ) : void
  36. + SearchSalEmp( String name) : Boolean
  37. Company
  38. - arr1[ ] : MonthlySalEmployee
  39. + addMonEmp(a : MonthlySalEmployee) : void
  40. + displayEmpList( ) :void
  41. Page 2 of 4
  42. a) Write in java the MonthlySalEmployee class having following attributes and behaviors:
  43. i. Basicpay: represents the basic pay of monthly salaried employee
  44. ii. Allowances : represents the allowances of monthly salaried employee.
  45. iii. getBasicpay() returns the employee basic pay & setBasicpay() change the employee
  46. basic pay
  47. iv. getAllowance( ) returns the employee allowance & setAllowance( ) changes the
  48. employee allowance
  49. v. getdata() takes information of employee as input
  50. vi. displayinfo() displays all information related to employee
  51. b) Write a Java class Company that contains the following attribute and methods:
  52. i. arr1[ ]: an array of objects of MonthlySalEmployee type
  53. ii. addMonEmp(a:MonthlaySalEmployee) adds objects of class MonthlySalEmployee in an
  54. array of objects (Max 5 employees can be added)
  55. QUESTION NO. 2 (reasoning questions) (05x1=05 Mark)
  56. Answer the following questions (maximum of 2 sentences)
  57. 1. Access specifiers determine whether a field or method in a class, can be used or invoked by
  58. another method in another class or sub-class. Consider that java also take non-access specifiers
  59. to restrict access. If the developer is willing to define class attributes and methods such that
  60. these are shared by all the objects of the class? Help the developer to identify the type and
  61. name of specifier.
  62. 2. Predict output of the following and explain the working also.
  63. public class University{
  64. public static void main(String[] args) {
  65.  int[] list = new int[]{1, 3, 5, 7, 9, 11, 15, 17, 19, 21};
  66.  System.out.println(list[8%3]);
  67. } }
  68. Page 3 of 4
  69. 3. Is following code correct? Yes/No? Explain the answer in either cases.
  70. 4. Do you think the below code compiles successfully even though it is calling super class’s
  71. protected constructor outside the package?
  72. 5. Read following paragraph carefully and answer the question given after this paragraph:
  73. Write 2 features of JAVA specifically defined / discussed in above paragraph.
  74. package one;
  75. class A
  76. {}
  77. package two;
  78. class B extends A
  79. {}
  80. package one;
  81. public class A
  82. {
  83.  protected A(int x)
  84.  {
  85.  //protected constructor
  86.  }
  87. }
  88. package two;
  89. import one.A;
  90. class B extends A
  91. {
  92.  public B()
  93.  {
  94.  super(100); //calling super class's protected constructor
  95.  }
  96. }
  97. JVM stands for Java Virtual Machine. Java code is compiled down into an intermediary
  98. language called byte code. The Java Virtual Machine is then responsible for executing this
  99. byte code. This is unlike languages such as C++ which are compiled directly to native code
  100. for a specific platform. This is what gives Java its ‘Write once, run anywhere’ ability.
  101. Page 4 of 4
  102. QUESTION NO. 3 (logic development) (2+2+1=05 Mark)
  103. Sparse matrices are matrices whose elements are predominantly zero. This question develops a Java
  104. representation for them called SparseMatrix. The code below seeks to use an ArrayList of LinkedLists
  105. to implement the concept efficiently. It defines a class Element to store the column number and value
  106. for an element. Each row is represented by a LinkedList of Elements with non-zero values only. Few, if
  107. any, rows are all zeros and so the ArrayList is used to store a LinkedList for every row in ascending row
  108. order. Read the given code carefully and answer the given questions:
  109.  
  110. public class Element
  111. {
  112. public int column;
  113. public int value;
  114. }
  115. public class SparseMatrix
  116. {
  117. private int mRows; // Number of rows
  118. private int mCols; // Number of columns
  119. private ArrayList<LinkedList<Element> > mMatrix; // Data
  120. }
  121.  
  122. 1. Give two reasons why Element should not have public state and provide a better mutable
  123. Element definition.
  124. 2. Explain why ArrayList and LinkedList are appropriate choices in this context. And if this is not an
  125. appropriate choice then which technique you will use to create a sparse matrix.
  126. 3. Write a constructor for SparseMatrix that takes arguments specifying the number of rows and
  127. columns and initializes state appropriately.
  128. ************************End of Paper**********************
  129.  
  130.  
  131.