0% found this document useful (0 votes)
10 views

Programming Fundamentals SAMPLE Final Exam

This document is a sample final examination paper for the Programming Fundamentals course, detailing the exam structure, rules, and instructions. It consists of multiple parts with various programming questions and coding tasks to assess students' understanding of programming concepts. The examination is strictly monitored, with specific guidelines on materials allowed and conduct during the exam.

Uploaded by

koximi1998
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Programming Fundamentals SAMPLE Final Exam

This document is a sample final examination paper for the Programming Fundamentals course, detailing the exam structure, rules, and instructions. It consists of multiple parts with various programming questions and coding tasks to assess students' understanding of programming concepts. The examination is strictly monitored, with specific guidelines on materials allowed and conduct during the exam.

Uploaded by

koximi1998
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Family Name: ______________________________

Given Name: ______________________________

Student Id: _________________________________

Tutor’s Name: ______________________________

Tutorial Day and Time: __________________________

FINAL EXAMINATION
SAMPLE – September 2017
IPRG001 / EPRG001

Time Allowed: 3 hours

Number of Questions: 20

Instructions: Answer ALL questions in this booklet

Materials Allowed: None (pen or pencil only)

This paper must not be removed from the examination room

N.B. A page for completing notes during the exam is attached to the end of this exam paper. This page
must not be removed from the exam room.

INSEARCH
CRICOS Provider Code: 00859D
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

IMPORTANT INFORMATION REGARDING THE EXAMINATION RULES

You must not try to get any help in these examinations or give help to any other
student.

You must not bring any unauthorised information or materials into the examination
room, toilets or in any other place visited by you during the examination.

Mobile phones must be switched off and placed under your chair for the duration
of the exam.

You must NOT have any writing on your body or write notes on your body during
the exam.

You must not make notes on any materials other than those provided.

Any items brought into the examination room must be available for inspection and
must be placed where directed by the supervisor.

Programmable calculators are not permitted and your calculator must not have a
cover, nor have anything written on it or any notes enclosed in it.

The examination paper and the answer sheets/booklets must not be removed from
the examination room. You are to remain seated until all examination papers and
answer sheets/booklets are collected.

You are not permitted to leave the examination room for any reason until 90
minutes of writing time has passed or within 15 minutes of the examination
concluding.

Any student who breaks the examination rules, is found cheating, behaves in a
disorderly manner or otherwise disrupts an examination will face disciplinary
action as determined by the Student Conduct Committee. Penalties include a zero
grade for the exam and exclusion from Insearch.

I have read and understand the above rules.

Signed ________________________________

2
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

Part A – 20 marks
All questions in Part A are worth 2 marks each
ANSWER ALL QUESTIONS IN THIS BOOKLET

1. Give an example of a valid value for the following data types:

a. char
b. int
c. String
d. boolean

2. Given the following method header, answer these questions:

public String getName(int ID)

a. What is the visibility modifier of the method?


b. What data type returned by the method?

3. Write down the correct way to declare and create an object using
the following Constructor method headers:

Book(String title, double cost, boolean inStock)

Tablet(float price, int number, char type)

3
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

4. Write the Java code to declare and initialise a constant to hold the
value true. You can name it anything you like, but you must choose
the most appropriate data type and assign it the value true.

5. What is the error in the following piece of code?

int j = 0, total = 0;
while (j<100)
{
total = total + j;
}
System.out.println(“total = “+total);

6. Write a for loop that adds up the numbers between 5 and 20


inclusive.

7. Given the following code, what will be the value stored in the
variable x after the code has executed?

double doubles[] = {5.2,8.1,4.7,6.3,8.0,6.5};


double x = doubles[3] + doubles[5];

4
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

8. What is the value of the variable k after the following code has been
executed?

int i = 23, j = 2;
double k = (double)i / j;

9. Write the method header for a function called isPopular() that


has two Person input parameters. It returns true if the first person has
more friends than the second person, and returns false otherwise.

10. Write down the values of the following:

int[][][] table3D = {{{5,7,4},{19,20,6}},


{{15,32,9},{7,8,3}},
{{79,13,11},{11,25,23}}};

a. table3D[0][1][0] =

b. table3D[1][0][1] =

5
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

Part B – 20 marks

Question 1
Write a class Student that has:
Attributes for name, ID and number of subjects
A Student constructor with three parameters used to initialise all
attributes in the class
Accessor and mutator for the student ID
A toString() method to display the Student details
A method that returns true or false depending on whether the
Student is full time (this is true of the Student is studying 4
subjects or more)

Write the code for class Student here:

6
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

Question 2 – 4 marks

The class University has an array of students as an attribute.

Write a method setupStudents() in class University that initialises


the first three students in the array.

public class University


{

Student students[] = new Student[20];

// Write the code for setupStudents() here:

7
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

Question 3 – 6 marks

Write a method searchStudents(int id) in class University that


searches an array of Students for the Student that has the ID entered as
the parameter.
If the Student is found in the array, display the Student details
(using toString() and return the Student object.
The method must stop searching the array when the Student is
found.
If the Student is not found, an error message must be displayed,
and null is returned.
Write the search in the most efficient way possible

public class University


{

Student students[] = new Student[20];

// Write the code for searchStudents () here:

8
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

Part C – 20 marks
There are two questions in Part C worth 10 marks each

Below is some code for three classes: they are Party, Australian and
French. Line numbers printed on the left are to be used in the questions,
they are NOT part of the Java code.

Question 1
Study the code carefully, then answer these questions:
a. (5 marks) Write down the line numbers in execution order,
starting from line number 6:

b. (1 mark) How many class attributes does the class Party have?

c. (1 mark) What is the value of the attribute timeAtParty in the


class Australian after line 12 has been executed?

d. (2 marks) What is the value of the attribute timeAtParty in the


class French after line 15 has been executed?

e. (1 mark) What is the value of the variable time printed on the


screen when line 16 is executed?

9
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

1 public class Party


2 { private Australian ausJulie;
3 private Australian ausTim;
4 private French freFleur;
5
6 public Party()
7 {
8 ausTim = new Australian("Tim");
9 freFleur = new French("Fleur");
10 ausJulie = new Australian("Julie");
11 int time = 90;
12 ausTim.updateTimeAtParty(time);
13
14 time = 125;
15 freFleur.updateTimeAtParty(time);

16 System.out.println("The value of time is now:


17 " + time);
18 }
19 }
20

21 public class Australian


22 {
23 private String name;
24 private int timeAtParty;
25
26 public Australian(String personsName)
27 {
28 name = personsName;
29 timeAtParty = 0;
30 }
31
32 public void updateTimeAtParty(int time)
33 {
34 if (time > 90)
35 time = time + 10;
36
37 timeAtParty = timeAtParty + time;
38 }
39 }
40

10
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

41 public class French


42 {
43 private String name;
44 private int timeAtParty;
45
46 public French(String personsName)
47 {
48 name = personsName;
49 timeAtParty = 10;
50 }
51
52 public void updateTimeAtParty(int time)
53 {
54 if (time > 90)
55 time = time + 10;
56
57 timeAtParty = timeAtParty + time;
58 }
59 }

11
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

Question 2
a. (4 marks) Write a function called double getNumberOfHours()
that asks the user to enter the total number of hours they wish to hire a
car for (as double) and returns the number of hours. If the number of
hours entered is less than or equal to zero, or greater than 300 the
function should return a value of -1.0 indicating the value is not within
the valid range.

Write the code for double getNumberOfHours() here:

12
PROGRAMMING FUNDAMENTALS SAMPLE FINAL EXAMINATION

b. (6 marks) Write the Constructor of the class CarHire that calls the
method getNumberOfHours(). If the hours entered was within the
valid range then display a confirmation message on the screen that
the car hire will proceed, and display the number of days for the car
hire ROUNDED TO TWO DECIMAL PLACES. Use the formula:

days = numberOfHours / 24;

If the hours entered was invalid (if -1.0 was returned from the function)
then display an error message to the user.

Write the code for the CarHire constructor here:

END OF EXAMINATION

13

You might also like