TITLE HET: DIPLOMA IN INFORMATION TECHNOLOGY
SUBJECT PROGRAMMING 2B
SUBJECT CODE PRG220
TEST/EXAM DP TEST MEMO
SEMESTER 2ND
DATE WRITTEN 26 SEPTEMBER 2014
TOTAL MARKS 120
DURATION 2 HOURS
PASS MARK 50
WEIGHTING 10%
EXAMINER NEELOFAR SHAIK
MODERATOR KERISHA GOVENDER
REQUIREMENTS:
Learner Requirements: Stationery and Examination Book
Equipment Requirements: PC with Notepad
This paper consists of:
1. Section A : Multiple Choice/True and False/Matching 40 marks
2. Section B : Short Questions 16 marks
3. Section C :Practical 64 marks
Please answer ALL questions.
PLEASE READ THE ASSESSMENT RULES AND REGULATIONS THAT FOLLOW
Learners are warned that contravening any of the examination rules or disobeying the
instructions of an invigilator could result in the examination being declared invalid. Disciplinary
measures will be taken which may result in the students’ expulsion from Damelin.
Damelin PRG220 1
ASSESSMENT RULES AND REGULATIONS
Please ensure that you have read and fully understand the following assessment rules and
regulations prior to commencing with your assessment:
1. To be permitted access to the examination, a learner must arrive with:
- an Identity Document or other official proof of identity (for example,
- a student card, passport or driver's licence card with photo); and
- the required exam stationery.
2. No learner may enter the examination room more than 30 minutes after the examination
sitting has commenced and no candidate may leave the room less than one hour after the
examination sitting has commenced.
3. No extra time will be allowed should a student arrive late.
4. All learners must sign the Attendance Register for the examination on arrival.
5. It is the responsibility of learners to familiarise themselves with the examination rules prior
to sitting for the examination.
6. All examinations are to be written on the date and time officially stipulated by the College.
7. It is the responsibility of learners to ensure that they are writing the correct paper and that
the question paper is complete
8. Cell phones must be switched off prior to entering the exam venue. Cell phones and
wallets may be placed under candidates' chairs rather than at the front of the room.
9. Learners may not handle cell phones or wallets during the exam.
10. No weapon of any description may be taken into the assessment room.
11. All personal belongings are to be placed at the front of the examination room. Personal
belongings brought to the examination are at the owner's risk.
12. Smoking is not permitted and learners will not be allowed to leave the examination room in
order to smoke
13. Once the examination has commenced, all conversation of any form between candidates
must cease until after candidates have left the room, after the examination.
14. Only the official College examination book, as supplied by the College, may be used.
15. Learners must ensure that their student number is written on the answer book.
16. Learners are responsible for ensuring that they follow the instructions in the examination
for submitting their answers.
17. Please read the instruction appearing on the examination paper carefully
18. The number of every question must be clearly indicated at the top of every answer.
19. No pages may be torn out of the answer book. All question papers and scrap paper must
be handed to the invigilator after the examination.
20. Learners finishing earlier are to leave the examination room as quietly as possible on the
instruction of the invigilator, and may not talk until outside the building where the
examination is being written.
21. Only under exceptional circumstances will a learner be permitted to leave the examination
room during the examination, and if the invigilator gives permission. An invigilator must
accompany the learner. Only one learner at a time may be absent from the examination
room.
22. Candidates may not act dishonestly in any respect.
Damelin PRG220 2
SECTION A [40 Marks]
Question One (20 MARKS)
Multiple Choice Questions
Write the correct letter next to the corresponding question number. Example: 1.1. a
1.1. A base class can also be called a ___________.
a. child class√√
b. subclass
c. derived class
d. superclass
1.2. ---------is a two-dimensional array that has rows of different lengths.
a. Ragged Array√√
b. Jagged Array
c. 1D ARRAY
d. 2D Array
1.3. A programmer created data type with a fixed set of values is an
a. enumerated data type√√
b. Static data type
c. Instance variable
d. Enum constant
1.4. ------------is the technique of using the same method name to indicate different
Implementations
a. Aggregation
b. Polymorphism√√
c. Inheritance
d. Information hiding
1.5. A collection of fields that contain data about an entity is a called a
a. Field rows
b. Record√√
c. Table
d. Csv
Damelin PRG220 3
1.6. An exception is an------
a. Exclusion of code
b. Expected error
c. Unexpected or error condition.√ √
d. Excluded comments
1.7. Applications that continue to operate when some part of the system fails.
a. Fault-tolerant applications√√
b. Mission critical applications
c. Available systems
d. Fault reliable
1.8. ------is where the computer stores the list of method locations to which the system
must return.
a. variable
b. call value
c. system calls
d. call stack√√
1.9. Buttons, text fields and other components that a user can interact with are called -----
a. UI components√√
b. GUI components
c. Swing handlers
d. Layout managers
1.10. Which of the following statements is true?
a. A child class inherits from a parent class.√ √
b. A parent class inherits from a child class.
c. Both of the preceding statements are true.
d. Neither a nor b is true.
Damelin PRG220 4
Question Two (10 Marks)
True and False Questions
Indicate whether the following statements are true or false.
Choose the answer and only write true or false next to the corresponding question number.
2.1. Variable names are not case sensitive. False√
2.2. A key field is the field in a record that holds the most sensitive information.
False
2.3. Businesses store data in random order when they use the records for batch
processing. False√
2.4. Typically, you place .class files in a package so other programmers can import them
into their programs. True√
2.5. You can use the keyword this from within a derived class method to access an
overridden base class method False√
2.6. An abstract method has no body, curly braces, or statements. True√
2.7. An advantage of the ArrayList class over the Arrays class is that an ArrayList is
dynamically resizable. True√
2.8. The following array contains two columns and three rows:
int[][] myArray ={{12, 14, 19},{33, 45, 88}}; False√
2.9. Exception Handling does not use make use of the try block False√
2.10. A derived class has access to all its parents’ non private methods. True√
Damelin PRG220 5
Question Three (10 Marks)
Matching
Choose a description from column B that matches a description in column A . Write only the
corresponding letter next to the question number.
Column A Column B
3.1. super a. derived class. H√
3.2. Array b. variable declared outside of any methods G√
declaration
3.3. Instance c. base class B√
Variables
3.4. ArrayList class d. is the character used to separate path components E√
3.5. Superclass e. provides a dynamically resizable container that stores lists C√
of objects.
3.6. Multiple f. actions you must perform at the end of a try...catch I√
inheritance sequence,
3.7. path delimiter g. double [] someNumbers = new double [20]; D√
3.8. Finally block. h. always refers to the superclass of the class in which you F√
use it.
3.9. subclass i. is the capability to inherit from more than one class A√
3.10. Sorting j. is the process of arranging a series of objects in some J√
logical order.
Damelin PRG220 6
SECTION B [16 Marks]
Question Four
Create instance methods (Accessor and Mutatator)for each instance variable, empNum,
lastName, firstName, salary (16)
public int getEmpNum()
return empNum;
public void setEmpNum(int emp)
empNum =emp;
public String getLastName()
return lastName;
public void setLastName(String name)
lastName = name;
Damelin PRG220 7
public String getFirstName()
return firstName;
public void setFirstName(String name)
firstName =name;
public double getSalary()
return salary;
public void setSalary(double sal)
salary =sal;
√√ 2 marks for each method.
Damelin PRG220 8
SECTION C [64 Marks]
Question Five (20 Marks)
Write a java application in which you declare an array of five integers and store five values in
the array. Write a try block in which you loop to display each successive element of the array,
increasing a subscript by 1 on each pass through the loop. Create a catch block that catches
the eventual ArrayIndexOutOfBoundsException and displays an appropriate message.
package gonetoofar;
public class Main {
public static void main(String[] args) {
int[] num = {2, 8, 4, 6, 7};
try {
for (int i = 0; i <= 10; i++) {
System.out.println(num[i]);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Damelin PRG220 9
Question Six (20 Marks)
The Integer.parseInt() method requires a String argument, but fails if the String cannot be
converted to an integer. Write an application in which you try to parse a String that does not
represent an integer value. Catch theNumberFormatException that is thrown, and then display
an appropriate error message.
package trytoparsestring;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num;
try
{
System.out.println("Enter a number");
num=input.nextInt();
}
catch (NumberFormatException e)
{
System.out.println(e.getMessage()+ "\n Please enter a numeric value");
}
}
Damelin PRG220 10
Question Seven (24 Marks)
Write a class called “Customer” that declares the instance variables idNumber and
balanceOwed.
Create a constructor that initializes each variable.
Create a display() method that would display the Customers id number and balance.
Write a “PreferredCustomer” class that extends the Customer class, Use constructors
including superclass constructors to initialize each variable. Declare a variable to hold the
discount value.
In the PreferredCustomer class create a display() method that invokes the parent version of
the display() method and also displays the discountRate.
Create an application called “TestCustomers” that instantiates an object for each class and
provides values for each instance variable.
package testcustomers;
public class Main {
public static void main(String[] args)
{
Customer oneCust = new Customer(124, 123.45);
PreferredCustomer onePCust = new PreferredCustomer(125, 3456.78, 0.15);
oneCust.display();
onePCust.display();
}
}
Damelin PRG220 11
package testcustomers;
public class Customer {
private int idNumber;
private double balanceOwed;
public Customer(int id, double bal) {
idNumber = id;
balanceOwed = bal;
}
public void display() {
System.out.println("Customer #" + idNumber
+ " Balance $" + balanceOwed);
}
}
package testcustomers;
public class PreferredCustomer extends Customer
{
double discountRate;
public PreferredCustomer(int id, double bal, double rate)
{
super(id, bal);
discountRate =rate;
}
public void display()
{
super.display();
System.out.println(" Discount rate is "+ discountRate);
}
}
Markers to use their discretion
Damelin PRG220 12