CSC435

Embed Size (px)

Citation preview

  • 8/12/2019 CSC435

    1/10

    CONFIDENTIAL

    CS/JAN 2013/CSC435

    UNIVERSITI TEKNOLOGI MARA

    FINAL EXAMINATION

    COURSE

    COURSE CODE

    EXAMINATION

    TIME

    OBJECT-ORIENTED PROGRAMMING

    CSC435

    JANUARY 2013

    3 HOURS

    INSTRUCTIONS TO CANDIDATES

    1. This question paper cons ists of two (2) parts : PART A (10 Que stions)

    PART B (6 Que stions)

    2. Answer ALL questions in the Answer Booklet. Start each answer on a new page.

    3. Do not bring any material into the exam ination room unless perm ission is given by the

    invigilator.

    4.

    Please check to make sure that this examination pack consists o f.

    i) the Que stion Paper

    ii) an Ans wer Book let - provided by the Faculty

    DO NOT TURN

    T IS

    PAGE

    UNTIL

    YOU ARE TOLD TO DO SO

    This examination pape r consists of

    1

    printed page s

    Hak Cipta Universi t i Teknologi MARA CONFIDENTIAL

  • 8/12/2019 CSC435

    2/10

    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. informa tion 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 ) ; }

    }//endclass

    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 C a l c u l a t e (...) is overloaded.

    D. The above program segment applies the passing parameter by value only.

    Hak Cipta Universiti Teknologi MARA

    CONFIDENTIAL

  • 8/12/2019 CSC435

    3/10

    CONFIDENTIAL

    3

    CS/JAN 2013/CSC435

    4. Given the following program seg m ent:

    public class PAQ4 {

    public static void main(String[] args) {

    String secretWord = Mississippi ;

    fo r i n t x = 10; x >0; x=x -2) {

    S y s t e m . o u t . p r i n t s e c r e t W o r d . c h a r A t x ) ) ; }

    }

    }//end c l a s s

    W hat is the output of the above program segment?

    A. sippi

    B. sispi

    C. ipsip

    D. ipsis

    5. Wh ich of the following examp les 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 EXC EPT

    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

  • 8/12/2019 CSC435

    4/10

    CONFIDENTIAL

    4

    CS/JAN 2013/CSC435

    By referring the U n i v e r s i t y c lass, determine the CORRECT Java code

    statements in the main program to update the chancellor's name. Assume that the

    object name is u n i .

    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 stateme nts areTRUEabout inheritance?

    i. Inheritance allows an object to inherit charac teristics from anothe r object,

    ii.

    An object is able to pass on its state and behaviors to its children ,

    iii.

    The objects need to have characteristics in comm on 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, comm on interface

    B. comm on interface, concrete

    C. methods sharing, extends

    D. protected, private

    10.

    Which of the following statements areTRUEabout reading and writing text file?

    i. It's almos t always a good idea to use buffering.

    ii.

    It's often possible to use references to abstract base classe s, 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 M ARA

    CONFIDENTIAL

  • 8/12/2019 CSC435

    5/10

    CONFIDENTIAL

    5

    CS/JAN 2013/CSC435

    PART B 80 MARKS )

    QUESTION 1

    a) Write a function named S p he re S u rf ac eA re a () 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 sp he re Vo lum e () 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 H ig he st S ph e re V o lu m e () 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)

    QUESTION2

    a) Academ ic 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 term s,

    i. class and object

    ii.

    overloading and overriding

    (4 marks)

    c) Explain four (4) advantages of Object Oriented approach .

    (4 marks)

    Hak Cipta Universi t i Teknologi MARA

    CONFIDENTIAL

  • 8/12/2019 CSC435

    6/10

    CONFIDENTIAL

    6

    CS/JAN 2013/CSC435

    QUESTION

    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 showsthedata m embersofPa perR ech eck ing c lass .

    pu bl ic cla ss PaperRechecking {

    / / a t t r i b u t e s :

    pri vat e Stri ng s tudID; / / s tu de nt id

    private String studName; //student name

    pr i va t e St ri n g subjec tCode ; / / sub je ct code, e. g: CSC435

    pr iv at e in t previousMark; / / t he mark obta ine d before the

    / /rechecking process

    pr i va t e in t newMark; / / the mark obt ain ed af t e r the

    / /

    rechecking process

    //methods :

    Constructors

    Mutators

    Retrievers

    Processor

    Printer

    }

    a) Writeafunction definitionforeachofthe following questions,

    i. Normal constructor.

    II. A mutator.

    Retrieverforany4attributes.

    (2.5 marks)

    (2.5 marks)

    (2 marks)

    IV A Processor named Disp layChanges ) which display the changesof

    mark. The following table shows the appropriate message that shouldbe

    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 changesofmark

    (3 marks)

    Hak Cipta Universiti Teknologi MARA

    CONFIDENTIAL

  • 8/12/2019 CSC435

    7/10

    CONFIDENTIAL

    7

    CS/JAN 2013/CSC435

    b) Writeaprogram segm entin themain programforeachofthe following questions.

    i. Createanarrayofobject named pR ec he ck ing andthearray sizeis100.

    (1 mark)

    ii. Display all subject codes, the changes of marks, total codes and total

    charges, recheckedby astudent named ANbinHassan .

    (4 marks)

    QUESTION

    4

    UiTMTopExecutivescanbeclassifiedas aRectorof acampusorDeanof afaculty. Given

    the followingareE x e c u t i v e s , CampusandF a c u l t y c lasses .

    Super class

    : E x e c u t i v e s

    Attr ibutes:

    St ri ng executiveName; //name of the executive

    Strin g de sign ati on; //example:

    Prof, or

    Associate

    Prof.

    St ri ng appo in tme nt Sta rt Date ; // fo rma t: dd/mm/yyyy

    St ri ng appointmentEndDate; // fo rm at : dd/mm/yyyy

    Subclass:

    Campus

    Attr ibutes:

    String campusCode;//example: 'R' for P e r l i s , D' for Terengganu

    String campusName; //name

    of the

    campus

    Str ing a rea ; / / l oca t i on

    of the

    campus

    Subclass:

    F a c u l t y

    Attr ibutes:

    String facultyCode;//example:

    FSG for

    Fakulti Sains Gunaan

    String facultyName;//nameof thefaculty

    a) Writeafunction definitionforeachofthe following questions.

    i. Norm al constructorforboth subclasses.

    (4 marks)

    ii.

    Retriever methods

    for

    E xe c u t i ve super c lass.

    (2 marks)

    iii.

    Printer me thods

    for

    both subc lasses.

    (3 marks)

    b) Writeaprogram segm entforeachofthe following questions.

    i. Declareanarray named ex ec s andthesizeofarrayofobjectis100.

    (0.5 marks)

    ii. Write a program segment to determine totals Rectors that have been

    appointedin 2012.

    (3 marks)

    Hak Cipta Universiti Teknologi M R

    CONFIDENTIAL

  • 8/12/2019 CSC435

    8/10

    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 ho lding imp ortant

    position of any clubs.

    Position Incentive Rate/Semester

    RIV

    Secretary RM 200

    Treasurer RM 150

    Table 1

    Table 2 shows the rate of incentives given to those students who are representing UiTM as

    players which depe nds on the p layer's level.

    ^ } ^^

    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 lubs

    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

    HakCipta Universiti Teknologi MARA CONFIDENTIAL

  • 8/12/2019 CSC435

    9/10

    CONFIDENTIAL 9 CS/JAN 2013/CSC435

    int totalCompetition; //total competition involved

    //in a semester

    a) Wr ite a method named C a lc u la t e in c e n t i v e s ( ) for both subc lasses, which

    return the total incentives as shown in Table 1and 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 s t u d .

    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 com petitions.

    (3 marks)

    QUESTION 6

    Given the fol lowing text f ile named Bo ok sB orr ow ed Ov erd ue . 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 dansaleh

    Suki Mohd Ali

    Jamil ah Ahmad

    Kursiah Kahari

    Johari Bilal

    zakaria Jalil

    jalal Hamid

    zalifah Rashid

    Kusin Ramli

    saliha Jasin

    shakir sal i in

    saliminsalam

    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^lv

    4 *

    12

    1

    8

    3

    7

    10

    4

    4

    6

    ./

    1

    8

    1

    1

    2

    3

    7

    4

    12

    2

    1

    :

    |

    6

    3

    Hak Cipta Universi t i Teknologi MARA

    CONFIDENTIAL

  • 8/12/2019 CSC435

    10/10

    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 f ile named Bo ok sB orr ow ed O ve rd ue . t x t .

    (5 marks)

    b) Wri te a program segment to produce the text f ile named O v e rd u e Ja n 2 0 1 2 . tx t

    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 201 2. 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 U niversiti Teknologi MARA

    CONFIDENTIAL