Final Schema

download Final Schema

of 15

Transcript of Final Schema

  • 8/7/2019 Final Schema

    1/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    1

    BAHAGIA A: SOALA STRUKTUR (70 MARKAH)

    SECTIO A: STRUCTURED QUESTIOS (70 MARKS)

    Arahan: Jawab semua soalan di dalam ruang kosong yang disediakan.

    Instruction: Answer all questions in the space provided.

    1. Berikan DUA (2) contoh storan sekunder.Give TWO (2) examples forsecondary storage.

    (2 markah/marks)

    Answer: Hard disks Floppy disks Zip disks CD-ROMs Tapes. Pendrive External hardisk

    2. Lengkapkan jadual berikut dengan jawapan yang BETUL.Complete the following table with a CORRECTanswer.

    (3 markah/marks)

    BahasaLanguage PeneranganDescription ContohExample PentafsirInterpreter

    Machine Arahan dalam bit 0 dan 1Instruction in 0 and 1 bits

    0111000011000001 Tiadaone

    Assembly Arahan dalam kod

    mnemonicInstruction in mnemoniccode

    LOAD 3

    STOR 4ADD

    PenghimpunAssembler

    High-level Menyamai bahasa manusiaseperti Java

    Similar to humanlanguage such as Java

    Marks = assignment+ exam

    Pengkompil &Penterjemah

    Compiler &interpreter

  • 8/7/2019 Final Schema

    2/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    2

    3. Berdasarkan kod Java di bawah dan jawab soalan-soalan berikut:Based on Java code below and answer the following questions:

    publicclass Test {staticfinalint TOTAL=100;

    publicstaticvoid main (String [] args){

    int raw_mark=50, mark;Test midtest=new Test();mark = midtest.calculate_Mark(raw_mark);System.out.println("Mark : "+ mark);}

    int calculate_Mark (int i){

    return (i/50)*TOTAL;

    }}

    a) Lukiskan gambar rajah kelas UML(Unified Modeling Language).Draw a UML (Unified Modeling Language) class diagram.

    (4 markah/marks)

    Answer:Test

    raw_mark :int

    mark: int

    Calculate_Mark

    b) Senaraikan SATU (1) objek dan SATU (1) pemalar.ListOE (1) object andOE (1) constant.

    (2 markah/marks)

    Answer:

    Object: midtestConstant : TOTAL

  • 8/7/2019 Final Schema

    3/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    3

    4. Nyatakan SATU (1) perbezaan di antara aplikasi dan applet Java.State OE(1) difference between Java application and Java applet.

    (2 markah/marks)

    Answer:

    Application can run on its own (stand alone) while applet must be run in abrowser (or applet viewer)

    Application must contain main() method while applet contain methods such as

    init(), paint() etc.

    5. Senaraikan DUA (2) tugas pengkompil Java.ListTWO(2) roles of Java compiler.

    (4 markah/marks)

    Answer:

    Check and detect syntax error in Java source codes.

    Convert the source codes from text format into bytecode format.

    6. Apakah perbezaan di antara kelakuan objek Scanner next() dan nextLine()?What is the difference between Scanner object method next() and

    nextLine()?

    (2 markah/marks)

    Answer:

    Method next() is used to read a single string token while method nextLine() is

    used to read a line of strings.

    7. Senaraikan DUA(2) perbezaan di antara ralat sintak dan ralat logik.ListTWO (2) of differences between syntax error and logic error

    (4 markah/marks)

    Answer:

    Syntax error Logic error

    Grammatical mistake in a program

    Compiler will detect

    Cannot execute the program

    A mistake caused by underlying

    algorithm

    Compiler cannot detect

    Can execute the program but produce

    incorrect results

  • 8/7/2019 Final Schema

    4/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    4

    8. Lukiskan simbol gambar rajah aktiviti berdasarkan definisi yang diberikan.Draw the activity diagram symbol based on the given definition.

    (4 markah/marks)

    Simbol/Symbol Definisi/Definition

    Titik tamat bagi program.Ending point of the program.

    Titik dimana aktiviti bercabang

    kepada beberapa alternatif bergantung

    kepada keadaan.

    A point where the activity may branch

    in alternative directions depending on

    a condition.

    Digunakan untuk menghubungkansimbol-simbol dan menentukan logik

    aliran.

    Used to connect the other symbolsand indicate the logic flow.

    Menentukan kawalan pada aliran

    Defining a guard on flow

    9. Diberi pernyataan deklarasi berikut:Given the following declaration statements:

    double value = 45.137293;

    String item = Product 1;

    int orderNo = 2;

    Tulis SATU (1) pernyataan Java menggunakan kelakuan printf() dan semua nilai

    pembolehubah yang telah diisytiharkan di atas untuk menghasilkan outputberikut:

    Write OE (1) Java statement using the printf() method and all the above

    declared variable values to produce the following output:

    The order number 2 has item:

    Product 1 with value RM45.14

    (4 markah/marks)

    Answer:

    System.out.printf(The order number %d has item:%n %s withvalue RM%5.2, orderNo, item, value);

  • 8/7/2019 Final Schema

    5/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    5

    10. Lengkapkan jadual berikut dengan menyatakan perbezaan di antara konstruktordengan kelakuan.

    Complete the following table by statingTWO (2) differences between constructorand method.

    (4 markah/marks)

    Penerangan/Description Konstruktor/Constructor Kelakuan/Method

    Nama

    ame

    Same as class name Not necessary same as

    class name

    Nilai dipulangkan

    Returning value

    No returning value Can be return value

    or not return vale

    11. Berdasarkan keratan aturcara di bawah, jawab soalan-soalan berikut.Based on the fragment of code below, answer the following questions.

    public void methodA (int i){System.out.println ("The value is"+ i);

    }

    public static void methodB (int j){System.out.println ("The value is"+ j);

    }

    public void methodC (int k){System.out.println ("The value is"+ k);

    }

    public static methodD (int l){System.out.println ("The value is"+ l);

    }

    a) Senaraikan kelakuan instance.List the instance method.

    (2 markah/marks)

    Answer:methodA and methodC

    b) Bagaimana untuk mendefinisikan kelakuan sebagai kelakuan kelas?How to define method as a class method?

    (2 markah/marks)

    Answer:Use the word static in the header of the method.

  • 8/7/2019 Final Schema

    6/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    6

    12. Apakah output dihasilkan oleh keratan aturcara Java berikut?What is the output produced by the following fragment of Java code?

    (6 markah/marks)

    Answer:Value of d is 1.5

    Value of b is -4

    13. Apakah output yang dihasilkan oleh keratan aturcara Java berikut?What is the output of the following Java program fragment?

    (4 markah/marks)

    int funny = 7, serious =15;funny = serious * 2;switch(funny){

    case 0: System.out.println("This is funny");break;

    case 30: System.out.println("This is serious");

    case 32: System.out.println("That is seriously funny");break;

    default: System.out.println(funny);}

    Answer:This is serious

    That is seriously funny

    int a=4, b=2, c=1;

    double d;

    c%=2;

    if (( c

  • 8/7/2019 Final Schema

    7/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    7

    int product =1,i=0;

    while (i

  • 8/7/2019 Final Schema

    8/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    8

    16. Berdasarkan pengisytiharaan String berikut, lengkapkan jadual berikut denganmengenalpasti nilai bagi setiap penyataan String yang diberi.

    Based on the following String declaration, complete the following table byidentifying value for each String statement.

    String str ="If it is raining today then there will be flood"

    (8 markah/marks)

    Penyataan String

    String Statement

    ilai

    Valuestr.indexOf('y) 21 1m

    str.endsWith(floods") False 1m

    str.lastIndexOf(o) 45 1m

    str.replace(o, u) If it is raining tuday then there will be fluud 1m

    "???" + str.length() +str.startsWith(I)

    ???47true 2m

    str.substring(2,4)+str.toUpperCase()

    iIF IT IS RAINING TODAY THEN THERE

    WILL BE FLOOD2m

    17. Berdasarkan keratan aturcara Java berikut, tuliskan nilai bagi setiap lokasitatasusunan list.

    Based on the following fragment of Java code, write down the valuefor eachlocation of list array.

    (5 markah/marks)

    int[] list = new double[5];list[4] = 11.11;list[0] = 44.44;list[1] = 33.33;list[2] = list[4] - list[3];

    list

    [0] [1] [2] [3] [4]

    Answer :list

    44.44 33.33 11.11 0.0 11.11

    [0] [1] [2] [3] [4]

  • 8/7/2019 Final Schema

    9/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    9

    BAHAGIA B: KAJIA KES (30 MARKAH)

    SECTIO B: CASE STUDY (30 MARKS)

    Arahan: Baca kajian kes di bawah dan jawab semua soalan-soalan berikut.

    Instruction: Read the case study below and answer all following questions.

    Bank Satu Malaysia memerlukan anda menulis satu aturcara bagi membantu pegawai di

    bahagian pinjaman untuk meluluskan permohonan pinjaman peribadi. Aturcara ini

    meminta pengguna memasukkan data pemohon iaitu pendapatan tahunan, tempoh tahun

    pinjaman, jumlah pinjaman dan status pelanggan. Status pelanggan adalah 0 jika

    pemohon adalah pelanggan biasa manakala status pelanggan adalah 1 bagi pelanggan

    terpilih. Permohonan diluluskan jika nilai jumlah pinjaman dibahagi dengan tempoh

    adalah kurang atau sama dengan pendapatan pemohon dibahagi dengan 12. Di samping

    itu, permohonan juga diluluskan jika pemohon berstatus pelanggan terpilih dan nilai

    jumlah pinjamannya dibahagi dengan tempoh adalah kurang atau sama dengan

    pendapatannya dibahagi dengan 10. Untuk kes yang lain permohonan adalah ditolak.

    Aturcara ini hendaklah memaparkan mesej ringkas memaklumkan pengguna tentangkeputusan permohonan. Kod pseudo untuk menentukan keputusan permohonan

    pinjaman adalah seperti berikut:

    The One Malaysia Bank wants you to write a program to help its loan officers approve personal loan applications. The program should prompt the user for the applicants

    yearly income, loan duration in years, amount of the loan and customer status. Thecustomer status is either 0 for a regular customer or 1 for preferred customer. Loan is

    approved if the loan amount divided by the duration is less than or equal to theapplicants income divided by 12. Also, approve the loan if the customer is a preferred

    customer and the amount of the loan divided by the duration is less than or equal to the

    applicants income divided by 10. In any other case, reject the application. The programshould display a simple message informing the user of its decision. The pseudo code to

    decide the loan application is as follows:

    Aturcara ini mestilah boleh memproses sebanyak manapun permohonan pinjaman. Jika

    pengguna memilih untuk berhenti memproses permohonan, aturcara ini hendaklah

    memaparkan jumlah pinjaman yang telah diluluskan dan jumlah pinjaman yang telah

    ditolak.

    The program must be able to process any number of loan applications. When the user

    decides not to process more applications, the program should display the total number ofapplications approves and the total number of applications rejected.

    if (amount / duration)

  • 8/7/2019 Final Schema

    10/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    10

    Berikut adalah contoh output bagi program tersebut:

    Following is the sample output of the program:

    Di dalam aturcara ini, 2 kelas akan ditakrifkan: kelas Loan dan kelas

    LoanApplication. Kelas Loan adalah digunakan untuk tujuan membuat keputusan

    tentang permohonan pinjaman. Ia hanya mempunyai satu kelakuan statik bernama

    decideLoan() yang mempunyai 4 parameter formal iaitu pendapatan tahunan, tempoh

    pinjaman, jumlah pinjaman dan status pelanggan. Kelakuan ini akan mengembalikan

    nilai true jika pinjaman diluluskan atau falsejika pinjaman ditolak (berdasarkan kodpseudo yang telah diberikan di atas).

    Kelas LoanApplication pula adalah aturcara utama yang mempunyai kelakuan

    main() yang akan mendapatkan data dari pengguna, memproses pinjaman denganmemanggil kelakuan decideLoan() dari kelas Loan dan memaparkan keputusan.

    Do you want to process a customer?Enter 1 for Yes, 0 for No: 1

    Enter income: 24000.00Enter duration in years: 4Enter amount of loan: 5000.00Enter customer status (0- regular, 1 preferred): 0The loan is approved.

    Do you want to process a customer?Enter 1 for Yes, 0 for No: 1Enter income: 24000.00Enter duration in years: 4Enter amount of loan: 10000.00Enter customer status (0- regular, 1 preferred): 0

    The loan is rejected.

    Do you want to process a customer?Enter 1 for Yes, 0 for No: 1Enter income: 24000.00Enter duration in years: 4Enter amount of loan: 10000.00Enter customer status (0- regular, 1 preferred): 1The loan is rejected.

    Do you want to process a customer?Enter 1 for Yes, 0 for No: 1

    Enter income: 24000.00Enter duration in years: 5Enter amount of loan: 10000.00Enter customer status (0- regular, 1 preferred): 1The loan is approved.

    Do you want to process a customer?Enter 1 for Yes, 0 for No: 0

    Number of loan approved: 2Number of loan rejected: 2

  • 8/7/2019 Final Schema

    11/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    11

    Semua langkah ini akan diulang sehinggalah pengguna memilih untuk berhenti yang akan

    menyebabkan bilangan permohonan yang diluluskan dan yang ditolak dipaparkan

    sebelum aturcara tamat.

    In this program, 2 classes will be defined: Loanclass andLoanApplication class.

    Loan class is used to decide the result of a loan application. It has only one static methodnameddecideLoan()which has 4 formal parameters: yearly income, loan duration,

    loan amount and customer status. This method returns true if loan is approved or

    false otherwise (based on the pseudocode given above).

    LoanApplication class is the main application which has the main() method that

    will get the required data from the user, process a loan by calling thedecideLoan()

    method ofLoan class and display the result. All of these steps will be repeated until the

    user decide to stop which subsequently resulted in the number of loan approved andnumber of loan rejected being printed before the program terminates

    a) Tuliskan definisi lengkap untuk kelakuan decideLoan() di dalam kelas Loanyang diberikan di bawah:

    Write a complete definition of method decideLoan()in the Loan class givenbelow:

    (9 markah/marks)

    public class Loan {

    }

  • 8/7/2019 Final Schema

    12/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    12

    b) Tuliskan kod pseudo untuk kelakuan utama di dalam kotak di bawah.Write a pseudo code for the main method in the box below.

    (6 markah/marks)

  • 8/7/2019 Final Schema

    13/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    13

    c) Tuliskan aturcara utama dengan lengkap di dalam kelas LoanApplicationberikut:

    Write a complete main program in the LoanApplication class below:

    (15 markah/marks)

    public class LoanApplication {public static void main(String [] args){

    }}

  • 8/7/2019 Final Schema

    14/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    14

    Answer:

    a)

    public class Loan {

    public static boolean decideLoan(double income,int duration, double amount, int status) {

    if ((amount / duration)

  • 8/7/2019 Final Schema

    15/15

    STIA1013 Pengaturcaraan Awalan/Introduction to Programming

    15

    c) marks are indicated as comments in the codes: