Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

BAZE UNIVERSITY, Abuja

Faculty of Computing and Applied Sciences


Level __200__Semester _First & Second__Examinations

_____AUGUST 2022________

Course Code : __COM201______

Course Title: _____Programming 1______________

Duration: ____Two (2) Hours_________

INSTRUCTIONS COM201-QP-22B

Section A
Total Marks 25
Answer ALL Questions in Section A

Section B
Total Marks 45
Answer ANY (ONE) Question from Section B

No electronic devices including mobile phones, wrist watch may be used


DO NOT turn the examination paper until instructed to do so

Continued overleaf …
SECTION A
[ Total Marks 25 ]
Answer All Questions from Section A
Question 1
a Declare and initialise a variable.

[1 Mark]
b. Write the syntax of a class

[1 marks]

c Write the syntax of a method and give an example


[1 marks]
d. Write a program to check if a number is above 100 or otherwise (if it is not). Print your
choice of output after you check the number.
[2 marks]
e. Write a program to print numbers in descending order using a for loop Use your
choice of number.
[3 marks]
f. Use the following GUI to answer question f-j

I. Declare a frame
II. Declare a label
III. Declare a text field
IV. Declare a button

[2 marks]

g.
I. What are the parameters for set bounds
II. Write the set bounds for atleast two of the components in f.

[3 marks]

h
I. What do you need to implement when you want an event to occur?
II. What method will you use after adding i.

[2 marks]

i
Add the components to the frame

[2 marks]

j
I. Write a for loop that prints even numbers from 2 -20 WITHOUT an if
statement
II. Write a while loop that prints even numbers from 2 - 20 WITHOUT an if
statement

[ 5 marks]

k
Correct the below code

Solve the error in the following – This is Java code

I. Declaration and intialization. Do not change the type of initialization.

int [] firstMultiArray = new int [3][3]

firstMultiArray[1][1] = 1;

firstMultiArray[1][2] = 2;

firstMultiArray[1][3] = 3;
II. Suppose (i) above has been corrected, fix the error below. The code
wants to print all values in the array – assuming all values have
been initialized.

for(int i = 1, i<=3, i++)

for(j = 1, j<3,j++) {

System.out.println(firstMultiArray[i][j])

}
[3 marks]

################## Continued overleaf …


SECTION B
[ Total Marks 45 ]
Answer any THREE Questions (Each question carries FIFTEEN marks).

Question 2:

a. Suppose you have been called to write a code that stores students’ grades in an array.
Each student has three [3] grades. Use any number as the number of students.
Initialise each location separately.

Write the codes to implement this AND explain why you have chosen to implement it
this way.
[5 Marks]
b.
Write the code that gives you the lowest and highest students score in question (a)
above.

[5 marks]

c.
Write the code that would change the scores of students that scored 38 and 39 to 40

[3 marks]

d.
Write the code that prints the number of A students in question (a) above.

[2 marks]

Question 3
a. I. Declare a 1-dimensional array with elements.
II. Initialise each location separately
III. Write the code to print each element backward. Do not use a for loop.

[5 marks]
b. I. Declare a 2-dimensional string array. The number of elements in rows and
columns should be different.
II. Initialise each location separately.
III. Check if the first letter of every element in the array is the same letter as the
last letter.
[5 marks]
c. I. Declare a 2-dimensional int array. The number of elements in rows and
columns should be different.
II. Initialise each location separately.
III. Get the elements that end with a zero.
[5 marks]

Question 4:
a. Write the code for creating a Frame with a title of your choice.
Add a label, textfield and button to this code.
Set bounds so that each element is directly below OR directly beside each other

[3 marks]

b. Using your answers in question (a) above, write the code for
I. Retrieving the number of characters in that text field in (I).
II. Retrieving the last letter from the text field in (I)
III. Displaying the value to labels - it should be a sentence with the value e.g
“number of letters is 4”.
IV. Checking to see if the value in the textfield is your student number and
displaying an appropriate sentence on a label.
NOTE: You do NOT need to write the code for the class or method. Write only relevant
codes in the method
[4 marks]
c. Write the code for retrieving a value from a text field and checking that the value is
above 18
[4 marks]

d. Suppose you have two buttons, show an example of how you could perorm an action
for the one that is clicked.
[4 marks]

Question 5 :
a.
Create a class for students and use the class to get and set results, name, age of
students.

Suppose you want to get and set students’ results - this is information that should not
be seen from outside the class, use encapsulation techniques to write the code for
the classes. Use the method in the appropriate class to calculate students' results.
State why you will use encapsulation for this.

[5 marks]
b. I. Create a class for 200 level courses, with all information about courses (You are
expected to write the code to include this information).
II. Now, create a class for programming 1. Write all the information class should have.
This class should use what was stored in the 200 level class (without re-writing the
code again).
III. What keyword is used to achieve this? What is this concept called?

Show the code for the above.


[5 marks]
ii
I. What are the types of polymorphism?
II. Show an example of each type polymorphism (mentioned in I).

[5 marks]

END OF EXAMINATION PAPER

You might also like