FINAL EXAMINATION COURSE COURSE CODE EXAMINATION TIME OBJECT-ORIENTED PROGRAMMING CSC435 JANUARY 2013 3 HOURS INSTRUCTIONS TO CANDIDATES 1. This question paper consists of two (2) parts : PART A (10 Questions) PART B (6 Questions) 2. Answer ALL questions in the Answer Booklet. Start each answer on a new page. 3. Do not bring any material into the examination room unless permission is given by the invigilator. 4. Please check to make sure that this examination pack consists of. i) the Question Paper ii) an Answer Booklet - provided by the Faculty DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO This examination paper consists of 10 printed pages Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 2 CS/JAN 2013/CSC435 PART A (20 MARKS ) 1. A/An is an operation which can modify an object behavior. A. attribute B. field C. method D. program 2. All the objects variables should be placed in the private access modifier,. These define the state of the object. As the name suggests, the variables are going to be private, that is they cannot be accessed from outside of the class declaration. This concept is known as . A. encapsulation B. information hiding C. polymorphism D. abstraction 3. Given the following program segment. public class PAQ3 { public static void main(String[] args) { int x = 3, y = -2, z = 0; Calculate(x,y,z); System.out.print(Calculate(y,z)); } public static void Calculate(int a, int b, c = a - b; } public static int Calculate (int p, int q) return (p - q); } }//end class int c) { { By referring the above program segment, which statement is FALSE? A. The result i s- 2. B. The result is - 7. C. The function Cal cul at e (...) is overloaded. D. The above program segment applies the passing parameter by value only. Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 3 CS/JAN 2013/CSC435 4. Given the following program segment: public class PAQ4 { public static void main(String[] args) { String secretWord = "Mississippi"; for ( i nt x = 10; x >0; x=x-2) { Sys t e m. out . pr i nt ( s e c r e t Wor d. c ha r At ( x) ) ; } } }/ / end c l a s s What is the output of the above program segment? A. sippi B. sispi C. ipsip D. ipsis 5. Which of the following examples shows receiving object as parameter? i. public static void XYZ (String name, Date dateOfBirth) ii. public static void XYZ (int x, int y) iii. public static int XYZ (Student stud) A. i only B. i and ii C. i and iii D. i,ii and iii 6. The following classes are predefined classes EXCEPT A. Date B. Double C. Animal D. Integer 7. Given the following program fragment. public class University { //attributes : private String uniCode; private String uniName; private String uniChancellorName; //methods : //Constructors //mutators //retrievers //printer } ipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 4 CS/JAN 2013/CSC435 By referring the Uni v er s i t y class, determine the CORRECT Java code statements in the main program to update the chancellor's name. Assume that the object name is uni . A. uni.setChancellorName(newChancellorName); B. uni.getChancellorName(newChancellorName); C. University uni = new University("IPTA03","Universiti Sains Malaysia", "DYTM Tuanku Raja Perlis"); D. University uni = new University("DYTM Tuanku Raja Perlis"); Which of the following statements are TRUE about inheritance? i. Inheritance allows an object to inherit characteristics from another object, ii. An object is able to pass on its state and behaviors to its children, iii. The objects need to have characteristics in common with each other. A. B. C. D. i only i and ii i and iii i,ii and iii 9. Polymorphism is an Object Oriented concept which advice use of instead of implementation. A. concrete, common interface B. common interface, concrete C. methods sharing, extends D. protected, private 10. Which of the following statements are TRUE about reading and writing text file? i. It's almost always a good idea to use buffering. ii. It's often possible to use references to abstract base classes, instead of references to specific concrete classes, iii. There is always a need to pay attention to exceptions. A. B. C. D. i and ii i and iii ii and iii i, ii and Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 5 CS/JAN 2013/CSC435 PART B (80 MARKS ) QUESTION 1 a) Write a function named SphereSurf aceArea () which calculate the area of sphere surface. The function receives the radius of sphere as integer data type of parameter from the main program and returns the surface area. The formula of sphere surface area is as follows. Sphere surface area = 4* pi* r 2 , where pi = 3.142 (2 marks) b) Write a function named sphereVolume () which calculate the volume of sphere. The function receives the radius of sphere as integer data type of parameter from the main program. Display the volume of sphere in the function. The formula of sphere volume is as follows. Sphere volume = (4/3)* pi * r 3 , where pi = 3.142 (2 marks) c) Write a function named Hi ghestSphereVol ume () which returns the highest volume of sphere. The function receives an array of variable as parameter which stores 10 different volumes of sphere volumes as double data type from the main program. (4 marks) QUESTION 2 a) Academic Affairs Department has suggested to InfoTech Department to develop an application to trace the UiTM graduates employability. The purpose of this application is to determine the marketability of UiTM Students' after graduation. Among the important information that are needed in the application are the duration of getting the job after graduate and the relevancy of the job with their field of studies. i. Identify the object. ii. List six (6) appropriate attributes. (4 marks) b) Explain the difference for each of the following terms, i. class and object ii. overloading and overriding (4 marks) c) Explain four (4) advantages of Object Oriented approach. (4 marks) Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 6 CS/JAN 2013/CSC435 QUESTION 3 The appeal process of paper rechecking is opened for two weeks after the result is announced to students. The charge of paper rechecking is RM 50 per paper. The following class shows the data members of PaperRechecki ng class. publ i c c l a s s PaperRechecki ng { / / a t t r i bu t e s : p r i va t e St r i ng st udID; / / s t u d e n t i d pr i va t e St r i ng studName; / / s t u d e n t name p r i va t e St r i ng subject Code; / / s ubj ect code, e. g: CSC435 pr i va t e i n t previ ousMark; / / t h e mark obt ai ned bef or e t he / / r echecki ng pr oces s pr i va t e i n t newMark; / / t he mark obt ai ned a f t e r t he / / r echecki ng pr ocess / / met hods : Constructors Mutators Retrievers Processor Printer } a) Write a function definition for each of the following questions, i. Normal constructor. II. A mutator. Retriever for any 4 attributes. (2.5 marks) (2.5 marks) (2 marks) IV. A Processor named Di spl ayChanges () which display the changes of mark. The following table shows the appropriate message that should be displayed. Previous Mark New Mark Message Higher Lower Lower Higher '"Sums K after recheck deducted Mark - newMark) The mark after recheck added (newMark - previousMark) No changes of mark (3 marks) Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 7 CS/JAN 2013/CSC435 b) Write a program segment in the main program for each of the following questions. i. Create an array of object named pRechecki ng and the array size is 100. (1 mark) ii. Display all subject codes, the changes of marks, total codes and total charges, rechecked by a student named "AN bin Hassan". (4 marks) QUESTION 4 UiTM Top Executives can be classified as a Rector of a campus or Dean of a faculty. Given the following are Execut i ves, Campus and Facul t y classes. Super class : Execut i ves Attributes: St r i ng executiveName; //name of t he execut i ve St r i ng de s i gna t i on; / / exampl e: Prof, or As s oci at e Prof. St r i ng appoi nt ment St ar t Dat e; / / f or mat : dd/mm/yyyy St r i ng appoi nt ment EndDat e; / / f or mat : dd/mm/yyyy Subclass : Campus Attributes: St r i ng campusCode; / / exampl e: 'R' for Pe r l i s , "D' for Terengganu St r i ng campusName; //name of t he campus St r i ng ar ea; / / l o c a t i o n of t he campus Subclass : Facul t y Attributes: String facultyCode;//example: 'FSG' for 'Fakulti Sains Gunaan' String facultyName;//name of the faculty a) Write a function definition for each of the following questions. i. Normal constructor for both subclasses. (4 marks) ii. Retriever methods for Execut i ve super class. (2 marks) iii. Printer methods for both subclasses. (3 marks) b) Write a program segment for each of the following questions. i. Declare an array named execs and the size of array of object is 100. (0.5 marks) ii. Write a program segment to determine totals Rectors that have been appointed in 2012. (3 marks) Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 8 CS/JAN 2013/CSC435 iii. Write a program segment to display all executives' names, faculty code and faculty name. (2.5 marks) QUESTION 5 Each student is required to enroll either registered club or sports as part of university graduation requirement. The student should maintain the enrollment until they are graduating. Among the registered clubs at UiTM are KEMBARA, Kebudayaan and Entrepreneurship. The registered sports are football, basketball, rugby, badminton and squash. The university gives some incentives to those students who are holding a position as presidents, secretary or treasurer of any clubs. Similarly to sports, the students will be given incentives when they are representing as UiTM players at any international or national competition. The incentive rate depends on the player's level either amateur or professional. Table 1 shows the rate of incentives given to those students who are holding important position of any clubs. Position Incentive Rate/Semester RIV Secretary RM 200 Treasurer RM 150 Table 1 Table 2shows the rate of incentives given to those students who are representing UiTM as players which depends on the player's level. J^^^}-^^^^^ Incentive Rate/Competition Ams Professional RM 120 Table 2 Given the following classes are student, Clubs and Sports. Super class : students Attributes : String studID; // student id String studName; // student name String studProg; // student program Subclass : Clubs Attributes : String clubName; // club name String clubPosition; // club position either president, // secretary, treasurer or none Subclass : Sports Attributes : String sportsName; // sports name String playerLevel; // players's level either amateur or // professional Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 9 CS/JAN 2013/CSC435 int totalCompetition; //total competition involved //in a semester a) Write a method named Cal cul at ei ncent i ves () for both subclasses, which return the total incentives as shown in Table 1 and Table 2. (6 marks) c) Write a program segment for each of the following questions. Assume that 100 records of students' profiles have been stored in an array of object named st ud. i. Write a program segment to determine total amateurs students' who are involved in the football game. (3 marks) ii. Write a program segment to determine total incentives that have been paid to all students who are holding a position as secretary in all clubs. (3 marks) iii. Write a program segment to search the student's name that has the highest involvement of competitions. (3 marks) QUESTION 6 Given the following text file named BooksBorrowedOverdue. t x t . File Edit Format |2011765482 2010647728 2010982718 2009121235 2008628892 2009277211 2008288383 2009123453 2007992911 2009123321 2008669925 2009187000 2009237333 2010200100 2011228929 2010889294 2011111921 2010101020 2010202021 2010201077 2011776631 2010010007 2008669925 View Help samiha Jamil Jamaliah Bakar Sabri Ahmad Jusoh zamri zaleha Buang Mail dan sal eh Suki Mohd Ali Jamil ah Ahmad Kursiah Kahari Johari Bilal zakaria Jalil jalal Hamid zalifah Rashid Kusin Ramli saliha Jasin shakir sal i in salimin sal am Baharin Bakar saliman zahir Ahamad Ali Mariah Mohamed Bakri Mas'ud zakaria Jalil Jan Feb Jan Mac Feb Apr Mei Mei Mei Mei Jun Jun Jul Jan Jul Jul ogo Sep Sep Sep Sep Sep okt 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 3 2 1 4 3 2 3 8 6 6 2 1 2 1 1 12 18 2 7 8 2 7 2 ,.c::;j l \ :.3 \ r^lvA 4 * 12 1 8 3 7 10 4 4 6 ./ 1 8 1 1 2 3 7 4 12 2 I 1 : | 6 3 Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 10 CS/JAN 2013/CSC435 Assume the above text file consists of thousands of records. The attributes of the above files are the student's ID, student's name, the month and year of overdue, total books which are overdue and total days of overdue. Write a program segment to perform the following tasks. a) Read all records from the file named BooksBorrowedOverdue. t x t . (5 marks) b) Write a program segment to produce the text file named OverdueJan201 2. t xt which stores all records of overdue in Jan 2012. (4 marks) c) Write a program segment to calculate the total charges of overdue collected in January and February 2012. Given the overdue charge is 20 cents per day per book. (4 marks) d) Use exception handling operations to deal with input and output errors. (2 marks) END OF QUESTION PAPER Hak Cipta Universiti Teknologi MARA CONFIDENTIAL