Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
KZN – DEPARTMENT OF
EDUCATION
GRADE 12
INFORMATION TECHNOLOGY
Trial Examination - 2008
MARKS: 120
TIME: 3 hours
This question paper consists of 3 questions and 15 pages.
Page 1 of 43
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
INSTRUCTIONS AND INFORMATION
1.
This is a three-hour examination. Because of the nature of this examination it is
important to note that you will not be permitted to leave the examination room
before the end of the examination session.
2.
You require the files listed below in order to answer the questions. They are either
on a stiffy disk or CD issued to you, or the invigilator/educator will tell you where to
find them on the hard drive of the workstation you are using or in a network folder.
QUESTION 1
Details.mdb
School.java
TestDatabase.java
QUESTION 2
Data.txt
QUESTION 3
Bookings.java
3.
If a stiffy disk or CD containing the above files was issued to you, write your name
and examination number on the label.
4.
Save your work at regular intervals as a precaution against power failures.
5.
Save ALL your solutions in folders with the number of the question and your
surname and name, for example Ques1_Black John.
6.
Type in your full name as a comment in the first line of each program.
7.
Read ALL the questions carefully. Do only what is required.
8.
At the end of this examination session you will be required to hand in the stiffy disk
or CD with all the files with the work you have done or you must make sure that
ALL the files with your work have been saved on the network as explained to you
by the invigilator/educator. Ensure that ALL files can be read.
9.
During the examination you may use Java API files. You may NOT refer to any
other resource material.
10.
Make printouts of the programming code of ALL the questions. Arrange the pages
of each question in the correct order and then the questions from QUESTION 1 to
3. Staple all the printouts of the questions (arranged correctly) in one batch to
hand in.
11.
All printing of programming questions will take place within an hour of the
completion of the examination.
Page 2 of 43
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION 1
The database Details.mdb, containing data related to the students and school-related
activities has been supplied in the folder named Ques1. The given database contains
the table named OldStudentTB.
The OldStudentTB table stores data related to the old/ex-students of the school.
The NewStudentTB table stores data related to new students who have siblings
that were old students.
You have also been supplied with an incomplete Java program in the folder named
Ques1 containing the files named School.java and TestDatabase.java.
Rename the folder Ques1 as Ques1_X (where X represents your surname and name).
e.g. Ques1_Black John.
The fields in this OldStudentTB table are defined as follows:
Field Name
StudentNo
Name
Surname
Year_Matriculated
Date_Of_Birth
Member_Fee_Owed
Town_City
Type
Number
Text
Text
Number
Date/Time
Currency
Text
Size/Format
4
20
25
Integer
Short date
R
20
The following is an example of the data stored in the OldStudentTB table.
Page 3 of 43
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
The fields in this NewStudentTB table are defined as follows:
Field Name
SiblingNo
NameNew
SurnameNew
Bursary
BursaryAmt
Type
Text
Text
Text
Yes/No
Currency
Size/Format
4
20
25
True/False
R
The following is an example of the data stored in the OldStudentTB table.
Open the School.java file. The connectivity code has already been written as part of
the given code. When you run the program, you have to enter the exact path where the
Details.mdb file has been stored.
Hint:
Copy the database into the root directory of the drive that you are working on.
The path to enter should be short, for example E:/Trials/Details.mdb.
Hint:
Instead of entering the path every time that you run the program, you can
change the input to a constant string containing the exact location of the
database, for example
String filename = ‘E:/Trials/Details.mdb’
Note: If you cannot establish connectivity with the database at all when you execute
the program, you must still complete and submit the programming code for
marking.
Marks will only be awarded for the programming code which contains the SQL
statements in the program named School.java.
Page 4 of 43
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
Complete the programming code in the School.java program by creating the necessary
SQL statements in the methods as specified below.
1.1
Complete the code in the method named selectAllQuery () by
formulating an SQL statement to display all the fields in the
OldStudentTB table sorted alphabetically according to the surnames of
the students. Place the statement in the appropriate line of the program
code. Example of output:
[3]
1.2
Complete the code in the method named selectPaidAll() by formulating
an SQL statement to display the Surname, Name and
Year_Matriculated fields in the OldStudentTB table of old students
who have paid their membership fees in full. Place the statement in the
appropriate line of the program code.
Example of output:
(4÷2)
[2]
Page 5 of 43
Please turn over
Information Technology
1.3
Grade 12
KZN-DoE/Trial Exam 2008
Complete the code in the method named select1998() by formulating
an SQL statement to display the Surname and Name fields in the
OldStudentTB table of old students from Pretoria who matriculated in
1998. Place the statement in the appropriate line of the program code.
Example of output:
(6÷2)
(3)
1.4
The school is planning a 5-year, 10-year and 15-year reunion function
for those who matriculated in 2003, 1998 and 1993. Complete the code
in the method named selectReunion() by formulating an SQL
statement to display the Name, Surname and Town_City fields of
those old students who need to be contacted for the reunion. Group the
data according to the Town_City field. Place the statement in the
appropriate line of the program code.
Example of output:
(10÷2)
(5)
Page 6 of 43
Please turn over
Information Technology
1.5
Grade 12
KZN-DoE/Trial Exam 2008
The school wishes to determine how much of the R100 membership fee
was paid by each old student. Complete the code in the method named
getPaid() by formulating an SQL statement to display the Name,
Surname and Paid fields. The Paid field is calculated by subtracting
the fee owed from R100. The values in the Paid field must be neatly
displayed including the currency R. Place the statement in the
appropriate line of the program code.
Example of output:
[4]
1.6
Complete the code in the method named aveFeeOwed () by formulating
an SQL statement to display the average of the fees owed.
Example of output:
Average of fees owed : R 19.43
1.7
1.8
[4]
Update the OldStudentTB table by changing all occurrences of Stanger to
KwaDukuza in the Town_City field.
[3]
Complete the code in the method named addData () by formulating an
SQL statement to add the following record to the OldStudentTB:
[3]
Name
Surname
John Grundy
Page 7 of 43
Year_Matriculated
Date_Of_Birth
1996
1977/08/09 R 100
Member_Fee_Owed
Town_City
Durban
Please turn over
Information Technology
1.9
Grade 12
KZN-DoE/Trial Exam 2008
Complete the code in the method named siblingQuery() by
formulating an SQL statement to display the NameNew and
SurnameNew fields of the new students who have bursaries and
the Name and Surname of the old student who is the sibling.
NB: You will need to link the tables with an appropriate WHERE clause to
be able to do this.
(8÷2)
(4)
1.10
Complete the code in the method named getBursary, by asking
the user to enter the SiblingNo. Formulate an SQL statement to
display the SurnameNew, NameNew and BursaryAmt fields of
the new student corresponding to the sibling number entered.
Place the statement in the appropriate line of the program code.
Example of input and output:
Enter the siblings number
167
Luscombe
Rambo
(6÷2)
(3)
9500
Total:
Page 8 of 43
[34]
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION TWO
This question aims at testing object-oriented programming skills. You are required to
produce a solution that includes all classes specified in the instructions/questions. No
marks will be allocated to any other solution such as one program without creating an
object.
Rename the folder Ques2 as Ques2_X (where X represents your surname and name)
e.g. Ques2_Black John
Examine the contents of a text file named Data.txt saved in the folder named Ques2.
The text file contains the surname and name of students as well as three marks for
English, Afrikaans and Mathematics, separated by a # character. The contents of the
text file is shown below.
Black#John#67#88#76
Dlamini#Patience#55#79#94
White#Heather#50#66#77
Singh#Jayce#63#74#63
NOTE: Type your name as a comment at the beginning of each class.
2.1
Create an object class named Students and save the file as Students.java in
the Ques2_X folder. This class should include code to do the following:
2.1.1 Define the following private fields:
Surname
(Surname)
Name
(First name)
Eng
(English mark)
Afr
(Afrikaans mark)
Mat
(Mathematics mark)
Ensure that you choose appropriate data types for these fields.
[3]
2.1.2 Create and initialise the fields in a default constructor as follows:
Surname = “”;
Name = “”;
Eng = 0;
Afr = 0;
Mat = 0;
[1]
Page 9 of 43
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
2.1.3 Create a parameterised constructor that will pass values for the
fields in the class. These parameters should be used to initialise
the fields of the class.
[3]
2.1.4 (a) Write a method named toString that returns information on
a student in one string formatted as follows:
Surname
Name
Eng
Afr
Mat
Example of the return strings for the 1st and 2nd students in
the Data.txt file:
Black
Dlamini
John
Patience
67
55
88
79
76
94
(b) Write a method named display that will display the contents
of the array. Use the following header:
public void display (Students [ ] arrStu, int n)
{
// Insert your code here
}
[7]
2.1.5 Write a method named getHigh to determine the highest mark of
the three marks obtained by each student.
[5]
2.1.6 Assume that the marks were entered incorrectly for a particular
student. Write a method named setNew that will receive three
new values for the student’s marks and change the current
values of the marks to the new values.
[4]
2.1.7 (a) Write a method named getEnglish to return the student’s
English mark.
(b) Write a method named getSurname to return the student’s
surname.
(c) Write a method named getName to return the student’s
name.
[3]
2.1.8 Write a method called findCass to calculate a CASS mark which
is the sum of one third of each of the three marks obtained.
[2]
Save the Students class
Page 10 of 43
Please turn over
Information Technology
2.2
Grade 12
KZN-DoE/Trial Exam 2008
Open the TestStudent class given to you.
2.2.1 Create an array caller arrStu (to hold a maximum of 10) that keeps
objects of Students. Write code to read data from the text file Data.txt
according to the following steps:
(a) Open the text file and initialise a loop to read the data.
(b) Read a line of text from the file.
(c) Separate the text into the surname, name and the three
mark values.
(d) Use this information to create a new Student object and
place the object into the array.
(e) Use a counter field to keep track of the number of elements
in the array.
[8]
2.2.2 Making use of the Students class as far as possible, write code for the
following; invoke (call) the relevant methods from the Student class.
(a) Display the details of each student.
(b) Sort the array in ascending order of the English mark and
display the details of all the students.
(c) Display the students’ surname, first name, highest mark and
CASS mark obtained.
(d)
Allow the user to enter the name (first name) of a student
whose marks need to be changed.
Allow the user to enter the new marks for English,
Afrikaans and Mathematics.
Search for this name in the array – and stop as soon as
the name is found.
Update the data and display the array.
If the named is not found, output a suitable message.
20 ÷ 2 =
Total:
Page 11 of 43
[10]
[46]
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION THREE
The school is holding a fashion show to raise funds. You have been asked to write a
program to keep track of seat-bookings for the show. A two-dimensional array is used
to represents the seating arrangement in the hall.
You have been supplied with an incomplete program in the folder named Ques3.
Rename the folder Ques3 as Ques3_X (where X represents your surname and
name) e.g. Ques3_Black John.
Open the java file in this folder named Bookings.java.
You are required to write the following methods in the Bookings class. Call the
methods in the main section of the class.
3.1
3.2
3.3
Declare a 15 x 20 two-dimensional array (where 15 represents the
number of rows and 20 represents the number of seats in each row.
[2]
Write a method named generate to initialise the array.
3.2.1 Randomly generate the numbers 0 and 1 to fill the array, where 0
represents an available seat and 1 represents a booked seat.
[4]
3.2.2 The first seat in each row is to be occupied by a teacher; set the
first seat in each row as booked.
[2]
Write a method named display that will display the seating plan in the
form of a grid as shown below. (Note: your data may vary due to
random selection being used).
Stage
ÏÏÏ1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0
ÏÏÏ1 0 0 0 0 1 1 0 0 1 0 0 0 1 0 0 0 0 1 0
ÏÏÏ1 1 0 1 0 1 1 1 1 1 1 1 0 1 1 0 1 0 1 1
ÏÏÏ1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 0
ÏÏÏ1 1 0 1 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1
ÏÏÏ1 0 1 0 0 0 1 0 1 0 1 1 1 0 0 0 1 0 1 1
ÏÏÏ1 0 1 0 0 1 0 0 0 0 1 1 0 1 0 1 1 1 1 0
ÏÏÏ1 0 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0
ÏÏÏ1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1
ÏÏÏ1 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1
ÏÏÏ1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 0 1 1 0 0
ÏÏÏ1 1 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 1 0 0
ÏÏÏ1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 0 1 0 0 1
ÏÏÏ1 0 1 1 0 1 0 0 1 0 0 1 0 1 1 1 1 0 0 1
ÏÏÏ1 0 1 0 1 0 1 0 0 1 1 0 1 0 0 1 1 1 0 1
[5]
Page 12 of 43
Please turn over
Information Technology
3.4
Grade 12
KZN-DoE/Trial Exam 2008
Write a method named reserve that will allow a person to make a
booking. Tickets in the first eight rows cost R50 each and those in the
last seven rows cost R40 each.
3.4.1 Read in the row (test that this number is in the correct range of 0
to 14) in which the booking is preferred and the number of tickets
required.
[5]
3.4.2 Change the required number of seats in that row to booked (1); if
the required number of seats is not available in the preferred row,
then only book the number of seats available. Display a suitable
message indicating that the required number of tickets are not
available.
[5]
3.4.3 Determine and display the total cost of the tickets booked.
[5]
SAMPLE RUN
Row in
Number
Only 5
Cost :
ÏÏÏ
ÏÏÏ1 0
ÏÏÏ1 0
ÏÏÏ1 1
ÏÏÏ1 1
ÏÏÏ1 1
ÏÏÏ1 0
ÏÏÏ1 0
ÏÏÏ1 0
ÏÏÏ1 1
ÏÏÏ1 1
ÏÏÏ1 0
ÏÏÏ1 1
ÏÏÏ1 0
ÏÏÏ1 0
ÏÏÏ1 0
3.5
which booking is required :
of tickets required : 9
seats avalable in that row
R 250
Stage
0 0 1 0 0 1 0 0 1 0 0 1 1 0
0 0 0 1 1 0 0 1 0 0 0 1 0 0
0 1 0 1 1 1 1 1 1 1 0 1 1 0
0 0 0 0 0 0 1 0 1 0 0 0 1 1
0 1 0 1 0 0 1 1 0 1 1 1 1 0
1 0 0 0 1 0 1 0 1 1 1 0 0 0
1 0 0 1 0 0 0 0 1 1 0 1 0 1
1 0 0 1 1 0 1 0 0 1 0 0 0 1
1 0 1 0 0 0 0 0 1 0 0 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 0 0 1 0 0
0 1 0 1 0 0 1 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0 1 1 1 0 1 0
1 1 0 1 0 0 1 0 0 1 0 1 1 1
1 0 1 0 1 0 0 1 1 0 1 0 0 1
9
0
0
1
0
0
1
1
0
0
1
1
1
1
1
1
0
0
0
0
1
0
1
0
0
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
1
0
0
0
0
0
0
0
1
0
1
1
0
0
1
1
0
0
1
1
1
Write a method named taken that will return the total number of seats
booked by the public.
Page 13 of 43
Please turn over
[4]
Information Technology
3.6
3.7
Grade 12
KZN-DoE/Trial Exam 2008
The most popular row is the row with the highest number of booked
seats – assume that there is only one such row. Write a method named
popular that will return the most popular row for booking.
(12÷2) =
[6]
Write a method named displayAll to display:
3.7.1 the total number of seats booked by the public with a suitable
message
[1]
3.7.2 The most popular row with a suitable message
[1]
SAMPLE RUN
The total number of seats booked : 154
The most popular row : 9
Page 14 of 43
Please turn over
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
Sample run of program
Stage
ÏÏÏ1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0
ÏÏÏ1 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0
ÏÏÏ1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 0
ÏÏÏ1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0
ÏÏÏ1 0 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 0 0 1
ÏÏÏ1 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 0
ÏÏÏ1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1
ÏÏÏ1 1 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1 0 0
ÏÏÏ1 1 1 0 1 1 0 0 1 0 0 0 1 1 1 0 0 0 0 1
ÏÏÏ1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 0
ÏÏÏ1 1 0 1 0 1 1 1 0 0 1 1 1 1 0 0 0 1 0 1
ÏÏÏ1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 0 1
ÏÏÏ1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 0 0 1 1
ÏÏÏ1 0 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 1
ÏÏÏ1 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 0
Row in which booking is required : 8
Number of tickets required : 2
ÏÏÏCost : R 80
Stage
ÏÏÏ1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0
ÏÏÏ1 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0
ÏÏÏ1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 0
ÏÏÏ1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0
ÏÏÏ1 0 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 0 0 1
ÏÏÏ1 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 0
ÏÏÏ1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1
ÏÏÏ1 1 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1 0 0
ÏÏÏ1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 0 0 0 0 1
ÏÏÏ1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 0
ÏÏÏ1 1 0 1 0 1 1 1 0 0 1 1 1 1 0 0 0 1 0 1
ÏÏÏ1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 0 1
ÏÏÏ1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 0 0 1 1
ÏÏÏ1 0 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 1
ÏÏÏ1 1 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 0
ÏÏÏThe total number of seats booked : 140
ÏÏÏThe most popular row : 11
Ï
Total:
Page 15 of 43
[40]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
KZN Trial Examination
2008
Information Technology
Paper 1
Marking Memo
Time: 3 hrs
Marks: 120
This memo consists of 3 questions and is printed on 13 pages
Page 16 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
Memo
QUESTION ONE
Total : 34
import java.sql.*;
import java.io.*;
import java.util.Scanner;
public class School
{
Connection conn;
public School ()
{
//load the driver
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println ("Driver successfully loaded");
}
catch (ClassNotFoundException c)
{
System.out.println ("Unable to load database driver");
}
//connect to the database
try
{
//conn = DriverManager.getConnection
("jdbc:odbc:Details.mdb");
//System.out.print("Type in the exact location of your
database (FOR EXAMPLE - C:/Details.mdb)");
//BufferedReader inKb = new BufferedReader (new
InputStreamReader (System.in));
//String filename = inKb.readLine();
String filename = "Details.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver
(*.mdb)};DBQ=";
database += filename.trim () + ";DriverID=22;READONLY=true}";
conn = DriverManager.getConnection (database, "", "");
System.out.println ("Connection to Details database
successfully established");
}
catch (Exception e)
{
System.out.println ("Unable to connect to the database");
Page 17 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
}
} //end connect
//1.1
public void selectAllQuery ()throws SQLException
{
Statement stmt = conn.createStatement ();
√
√
√
String sql = "SELECT * FROM OldStudentTB ORDER BY Surname"; (3)
ResultSet rs = stmt.executeQuery (sql);
System.out.printf("%-20s%-20s%-20s%-20s%-20s%20s","Name","Surname","Year_Matriculated","Date_Of_Birth","Member_Fee_Owed","
Town_City");
System.out.println();
System.out.println("==========================================================
=============================================================");
while (rs.next())
{
String cName = rs.getString ("Name");
String cSurname = rs.getString ("Surname");
String cMatric = rs.getString ("Year_Matriculated");
Date cDOB = rs.getDate ("Date_Of_Birth");
double cFee = rs.getDouble ("Member_Fee_Owed");
String cTown = rs.getString("Town_City");
System.out.printf("%-20s%-20s%-20s%-20s%-20.2f%20s",cName,cSurname,cMatric,cDOB,cFee,cTown);
System.out.println();
}
System.out.println(" ");
stmt.close ();
}
//1.2
public void selectPaidAll ()throws SQLException
{
Statement stmt = conn.createStatement ();
√
String sql = "SELECT Surname,Name,Year_Matriculated FROM" +
"OldStudentTB √WHERE √Member_Fee_Owed = 0"√;
(4÷2=2)
ResultSet rs = stmt.executeQuery (sql);
System.out.printf("%-20s%-20s%20s","Surname","Name","Year_Matriculated");
System.out.println();
System.out.println("==========================================================
============");
while (rs.next ())
{
String cSurname = rs.getString ("Surname");
String cName = rs.getString ("Name");
int cMatric = rs.getInt ("Year_Matriculated");
System.out.printf("%-20s%-20s%-20s",cSurname,cName,cMatric);
System.out.println();
Page 18 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
}
System.out.println(" ");
stmt.close ();
} //select
//1.3
public void select1998 ()throws SQLException
{
System.out.println("\f");
System.out.println();
Statement stmt = conn.createStatement ();
String sql = "SELECT Surname,Name √FROM OldStudentTB√ WHERE√"+
"Town_City = 'Pretoria'√ AND√ Year_Matriculated = 1998√"; (6÷2=3)
ResultSet rs = stmt.executeQuery (sql);
System.out.printf("%-20s%-20s","Surname","Name");
System.out.println();
System.out.println("===================================================");
while (rs.next ())
{
String cSurname = rs.getString ("Surname");
String cName = rs.getString ("Name");
System.out.printf("%-20s%-20s", cSurname,cName);
System.out.println();
}
System.out.println(" ");
stmt.close ();
}
//1.4
public void selectReunion ()throws SQLException
{
System.out.println("\f");
System.out.println();
Statement stmt = conn.createStatement ();
String sql = "SELECT Name,Surname,Town_City √FROM OldStudentTB √
WHERE √Year_Matriculated IN √√ (2003, √1998, √1993√)ORDER BY Town_City";√√
(10÷2=5)
ResultSet rs = stmt.executeQuery (sql);
System.out.printf("%-20s%-20s%-20s","Name","Surname","Town_City");
System.out.println();
System.out.println("====================================================");
while (rs.next ())
{
String cName = rs.getString ("Name");
Page 19 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
String cSurname = rs.getString ("Surname");
String cTown = rs.getString ("Town_City");
System.out.printf("%-20s%-20s%-20s",cName,cSurname,cTown);
System.out.println();
}
System.out.println(" ");
stmt.close ();
}
//1.5
public void getPaid()throws SQLException
{
System.out.println("\f");
System.out.println();
Statement stmt = conn.createStatement ();
String sql ="SELECT Name,Surname√,FORMAT(100-Member_Fee_Owed, √'Currency'√)"
+ "AS Paid √FROM OldStudentTB√";
(5)
ResultSet rs = stmt.executeQuery (sql);
System.out.printf("%-20s%-20s%-20s","Name","Surname", "Paid");
System.out.println();
System.out.println("==========================================================
======");
while (rs.next ())
{
String cName = rs.getString ("Name");
String cSurname = rs.getString ("Surname");
String cPaid = rs.getString("Paid");
System.out.printf("%-20s%-20s%-20s",cName,cSurname,cPaid);
System.out.println();
}
System.out.println(" ");
stmt.close ();
}
//1.6
public void aveFeeOwed()throws SQLException
{
System.out.println("\f");
System.out.println();
Statement stmt = conn.createStatement ();
String sql = "SELECT AVG(Member_Fee_Owed) √ AS Average√"+
"FROM OldStudentTB"√;
ResultSet rs = stmt.executeQuery(sql);
System.out.println();
System.out.println();
while (rs.next ())
{
double ave = rs.getDouble ("Average");
System.out.print("The average of fees owed :R");
Page 20 of 43
(3)
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
System.out.printf("%4.2f",ave);
}
System.out.println();
System.out.println();
stmt.close ();
}
//1.7
public void updateData() throws SQLException
{
Statement stmt = conn.createStatement ();
String sql = "UPDATE OldStudentTB √SET Town_City ='KwaDukuza'√"+
"WHERE Town_City = 'Stanger'√";
(3)
stmt.executeUpdate (sql);
System.out.println (" Updated ");
stmt.close();
}
//1.8
public void insertQuery () throws SQLException
{
Statement stmt = conn.createStatement ();
String sql = "INSERT INTO OldStudentTB√ (Name,Surname," +
"Year_Matriculated,Date_Of_Birth,Member_Fee_Owed,Town_City)"
"VALUES√ ('John','Grundy',1996,#1977/08/09#,100,'Durban') √";
stmt.executeUpdate (sql);
(3)
System.out.println (" Record inserted");
stmt.close ();
}
//1.9
public void siblingQuery()throws SQLException
{
System.out.println("\f");
System.out.println();
Statement stmt = conn.createStatement ();
String sql = "SELECT NameNew AS NewName√, SurnameNew AS"+
"NewSurname√,Name,Surname √FROM "NewStudentTb, √OldStudentTB"√
+ "WHERE √SiblingNo = StudentNo√ AND Bursary = TRUE";√
(8÷2=4)
ResultSet rs = stmt.executeQuery (sql);
System.out.printf("%-20s%-20s%-20s%20s","NewName","NewSurname","Name","Surname");
System.out.println();
Page 21 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
System.out.println("==========================================================
==");
while (rs.next ())
{
String cNewName = rs.getString ("NewName");
String cNewSurname = rs.getString ("NewSurname");
String cName = rs.getString ("Name");
String cSurname = rs.getString ("Surname");
System.out.printf("%-20s%-20s%-20s%20s",cNewName,cNewSurname,cName,cSurname);
System.out.println();
}
System.out.println(" ");
stmt.close ();
}
//1.10
public void busaryQuery()throws SQLException
{
System.out.println("\f");
System.out.println();
Scanner kb = new Scanner(System.in);
System.out.println("Enter the Sibling No");
int sNum = kb.nextInt();√
Statement stmt = conn.createStatement ();
String sql = "SELECT NameNew AS NewName√, SurnameNew AS
NewSurname√,BursaryAmt FROM NewStudentTb √WHERE SiblingNo√ ="+sNum√;
ResultSet rs = stmt.executeQuery (sql);
(6÷2=3)
System.out.printf("%-20s%-20s%-20s","NewSurname","NewName",
"BursaryAmt");
System.out.println();
System.out.println("========================================================")
;
while (rs.next ())
{
String cNewSurname = rs.getString ("NewSurname");
String cNewName = rs.getString ("NewName");
double cBursaryAmt = rs.getDouble ("BursaryAmt");
System.out.printf("%-20s%-20s%20.2f",cNewSurname,cNewName,cBursaryAmt);
System.out.println();
}
System.out.println(" ");
stmt.close ();
}
public void disconnect () throws SQLException
{
Page 22 of 43
Information Technology
conn.close ();
}
}
Page 23 of 43
Grade 12
KZN-DoE/Trial Exam 2008
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION TWO – SOLUTION ONE
46
Total :
public class Students
{
//2.1.1 Declare fields
private String Surname;
private String Name;
private int Eng;
private int Afr;
[3]
//2.1.2 Default constructor
public Students()
{
Surname = "";
Name = "";
Eng = 0;
Afr = 0;
}
[1]
//2.1.3 Parameterised constructor
public Students(String sn, String nm, int en, int
af, int ma)
{
Surname = sn;
Name = nm;
Eng = en;
Afr = af;
Mat = ma;
[3]
}
//2.1.4 Output string
public String toString()
{
String data = Surname + getSpaces(Surname,15) + Name
+ getSpaces(Name,15) + Eng + getSpaces(" "+Eng,8) + Afr +
getSpaces(" "+Afr,8) + Mat + getSpaces(" "+Mat,8;
return data;
public void display(Students[]arrStu,int n)
{
for (int i = 0; i < n; i++)
{
System.out.println(arrStu[i]);
}
}
[7]
Page 24 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
// Insert spaces
String getSpaces(String s, int w)
{
String spaces = "";
for (int i = 0; i < w - s.length(); i++)
{
spaces = spaces + " ";
}
return spaces;
}
//Heading
public void heading()
{
System.out.println("Surname" + getSpaces("Surname",15) +
"Name" + getSpaces("Name",15) + "Eng" + getSpaces("Eng",8) +
"Afr" + getSpaces("Afr",8) + "Mat" + getSpaces("Mat",8) +
"Ave");
}
//2.1.5 Determine highest
public int getHigh()
{
int max = 0;
if (Mat > Eng && Mat > Afr)
{
max = Mat;
}
else
if (Eng > Mat && Eng > Afr)
{
max = Eng;
}
else
{
max = Afr;
}
return max;
}
//2.1.6 Obtain new marks
public void setNew(int e, int a, int m)
{
Eng = e;
Afr = a;
Mat = m;
}
Page 25 of 43
[5]
[4]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
//2.1.7 Get English mark & Surname & name
public int getEnglish()
{
return Eng;
}
public String getSurname()
{
return Surname;
}
public String getName()
{
return Name;
}
}
[3]
//2.1.8
Calculate CASS mark
public int findCass()
{
int ans = (Eng + Afr + Mat) /3
return ans;
}
[2]
Page 26 of 43
Information Technology
import
import
import
import
Grade 12
KZN-DoE/Trial Exam 2008
java.lang.*;
java.util.Scanner;
java.io.*;
java.text.DecimalFormat;
public class UseStudents
{
UseStudents()
{
Scanner kb = new Scanner(System.in);
Students [] arrStu = new Students[10];
Students obj = new Students();
Students temp = new Students();
Scanner inp = null;
//2.2.1
Reading from the text file
try
{
inp = new Scanner (new File ("Data.txt"));
}
catch (FileNotFoundException e)
{
System.out.println("File not found");
}
int i= 0;
while (inp.hasNext())
{
String [] line = (inp.nextLine()).split("#");
String sur = line[0];
String nam = line[1];
int en = Integer.parseInt(line[2]);
int af = Integer.parseInt(line[3]);
int ma = Integer.parseInt(line[4]);
arrStu[i] = new Students(sur,nam,en,af,ma);
i++;
}
Page 27 of 43
[8]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
//2.2.2 (a)
obj.display(arrStu,i);
// 2.2.2 (b)
for (int j = 0; j < i-1; j++)
{
for (int k = j+1; k < i; k++)
{
if (arrStu[j].getEnglish() >
arrStu[k].getEnglish())
{
temp = arrStu[j];
arrStu[j] = arrStu[k];
arrStu[k] = temp;
}
}
}
System.out.println("Sorted list");
obj.display(arrStu,i);
//2.2.2 c
System.out.println("Names and highest marks");
for (int j = 0; j < i; j++)
{
System.out.println(arrStu[j].getSurname() + " " +
arrStu[j].getName() + " " + arrStu[j].getHigh()+ " " +
arrStu[j].findCass());
}
Page 28 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
//2.2.2 d
System.out.print("Enter name to edit : ");
String nam = kb.nextLine();
int k = 0;
boolean found = false;
while (!(found) && (k < i))
{
String sName = arrStu[k].getName();
if (sName.equalsIgnoreCase(nam))
{
found = true;
System.out.print("Enter new English mark : ");
int nEng = kb.nextInt();
System.out.print("Enter new Afrikaans mark:");
int nAfr = kb.nextInt();
System.out.print("Enter new Maths mark : ");
int nMat = kb.nextInt();
arrStu[k].setNew(nEng, nAfr,nMat);
}
k++;
}
if (!(found)
System.out.println("Name not in list");
else
obj2.display(arrStu,i);
}
//Main
public static void main(String [] args)
{
new UseStudents();
}
}
Page 29 of 43
20 ÷2 = [10]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION TWO – ALTERNATE SOLUTIONS
public class Students
{
private
private
private
private
private
√String surname ;
String name ; √
int eng ;
int afk ;
int maths; √
public Students()
{
}√
public Students(String s,String n,int e,int a,int m) √
{
surname = s;
name = n; √
eng = e;
afk = a;
maths = m; √
}
[3]
[1]
[3]
public String spaces(String s,int w)
{
String spc = "";
for(int loop=0; loop<w-s.length(); loop++)
{
spc = spc + " ";
}
spc = s + spc;
return spc;
}
public String toString()
{
String temp = "";
temp = spaces(surname,20) √ +spaces(name,20) √ +spaces(eng+"",10) √
+spaces(afk+""√,10) √ +spaces(maths+"",10) √;
return temp; √
[7]
}
public int getHigh()
{
int high = eng; √
if(afk > high) √
{
high = afk;
}
if(maths > high) √
{
high = maths; √
Page 30 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
}
return high; √
[5]
}
public void setNew(int e,int a,int m) √
{
eng = e; √
afk = a; √
maths = m; √
}
[4]
public int getEnglish()
{
return eng; √
}
public String getSurname()
{
return surname; √
}
public String getName()
{
return name; √
}
public int findCass()
{
int cass = (eng/3) + (afk/3) + (maths/3); √
return cass; √
}
}
import java.io.*;
Page 31 of 43
[3]
[2]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
import java.util.*;
public class TestStudent
{
private Students [] arrStu = new Students[10];
private int size=0;
Scanner kb = new Scanner(System.in);
public TestStudent()
{
try
{
Scanner scFile = new Scanner(new FileInputStream("Data.txt")√);
String line="",sName="",fName="";
int e,a,m; √
while(scFile.hasNext())√
{
line = scFile.nextLine();√
Scanner sc = new Scanner(line).useDelimiter("#");√
sName = sc.next();
fName = sc.next();
√
e = sc.nextInt();
a = sc.nextInt();
m = sc.nextInt();
arrStu[size] = new Students(sName,fName,e,a,m); √
size++;√
}
scFile.close();
[8]
}
catch(FileNotFoundException e)
{
System.out.println("Error Reading from Text File"+ e);
}
}
public void display()
{
for(int i=0; i<size; i++)
{
System.out.println(arrStu[i].toString()); √
(1)
}
System.out.println();
}
Page 32 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
public void sort()
{
Students temp;
for(int i=0; i<size-1; i++)
√
{
for(int j=i+1; j<size; j++)
{
if(arrStu[i].getEnglish() > arrStu[j].getEnglish())√
{
temp = arrStu[i];
arrStu[i] = arrStu[j];
arrStu[j] = temp;
√
}
}
}
System.out.println(“Sorted list”);
Display();√
(4)
}
public void displayRelevant()
{
for(int loop=0; loop<size; loop++)√
{
System.out.println(spaces(arrStu[loop].getSurname(),20)+
spaces(arrStu[loop].getName(),20) + spaces(arrStu[loop].getHigh()√
+"",10) + spaces(arrStu[loop].findCass()+"",10) √);
(3)
}
System.out.println();
}
public String spaces(String s,int w)
{
String spc = "";
for(int loop=0; loop<w-s.length(); loop++)
{
spc = spc + " ";
}
spc = s + spc;
return spc;
}
Page 33 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
public void update()
{
System.out.println("Enter the First Name of The student who
requires to be Updated!");
String nam = kb.next();√
boolean flag = false; √
int i = 0;
while(i<size√ && !flag) √
{
if(arrStu[i].getName()√.equalsIgnoreCase(nam)) √
{
flag = true;
System.out.println("Enter the Student's English Mark");
int e = kb.nextInt();
System.out.println("Enter the Student's Afrikaans Mark");√
int a = kb.nextInt();
System.out.println("Enter the Student's Mathematics Mark");
int m = kb.nextInt();
arrStu[i] √.setNew(e,a,m); √
System.out.println("Student's Details Updated!");
arrStu[i].toString();√
}
i++;√
}
if(!flag) √
{
System.out.println("The learner was NOT Located!");
(12)
}
[20÷2=10]
}
public static void main(String [] args)
{
TestStudent obj = new TestStudent();
obj.display();
obj.sort();
obj.displayRelevant();
obj.update();
}
}
Page 34 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION THREE
import java.lang.*;
import java.util.Scanner;
import java.io.*;
Total : 40
public class Bookings
{
// Create an object for input
Scanner kb = new Scanner(System.in);
//3.2
Generate data for the array
public void generate(int[][] A)
{
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 20; j++)
{
A[i][j] = (int)(Math.random()*2);
}
}
for (int i = 0; i < 15; i++)
{
A[i][0] = 1;
}
}
//3.3 Display Array
public void display(int[][] A)
{
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 20; j++)
{
System.out.print(A[i][j]+" ");
}
System.out.println();
}
}
Page 35 of 43
[6]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
[5]
Page 36 of 43
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
//3.4 Resesrve the seat & determine c
public void reserve(int[][] A)
{
int row = 0;
//Input row & test
do
{
System.out.print("Row in which booking is
required : ");
row = kb.nextInt();
}
while (row < 0 || row > 14); OR other correct forms
//Input number of tickets
System.out.print("Number of tickets required : ");
int num = kb.nextInt();
//Book seats
int count = 0;
int j = 1;
while (count < num && j < 20)
{
if (A[row][j] == 0)
{
A[row][j] = 1;
count++;
}
j++;
}
if (count < num)
{
System.out.println("Only "+count+" seats
available in that row");
}
//Determine cost
int cost = 0;
if (row < 8)
{
cost = count * 50;
}
else
{
cost = count * 40;
}
System.out.println("Cost : R " + cost);
}
Page 37 of 43
[15]
Information Technology
//3.5
Grade 12
KZN-DoE/Trial Exam 2008
Number of seats taken
public int taken(int A[][])
{
int booked = 0;
for (int i = 0; i < 15; i++)
{
for (int j = 0; j < 20; j++)
{
if (A[i][j] == 1)
{
booked ++;
}
}
}
return booked;
}
//3.6 Most popular row
public int popular(int A[][])
{
int[] high = new int[15];
for (int i = 0; i < 15; i++)
{
high[i] = 0;
for (int j = 0; j < 20; j++)
{
if (A[i][j] == 1)
{
high[i]++;
}
}
}
int pop = -1;
int max = high[0];
for (int i = 0; i < 15; i++)
{
if (high[i] > max)
{
max = high[i];
pop = i;
}
}
return pop;
}
Page 38 of 43
[4]
12 ÷ 2 =
[6]
Information Technology
//3.7
Grade 12
KZN-DoE/Trial Exam 2008
Display other details
public void displayAll(int A[][])
{
System.out.println("The total number of seats booked :
"+taken(A));
System.out.println("The most popular row :
"+popular(A));
}
[2]
//Display Heading
public void displayHeading(String header)
{
System.out.println(header);
}
public static void main(String args[])
{
// 3.1 Declare variables
int [][] seats = new int[15][20];
[2]
//Create an object called ck for calls
Bookings ck = new Bookings();
//Method Calls
ck.generate(seats);
ck.displayHeading("
ck.display(seats);
ck.reserve(seats);
ck.displayHeading("
ck.display(seats);
ck.displayAll(seats);
}
}
Page 39 of 43
Stage");
Stage");
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
QUESTION THREE – ALTERNATE SOLUTION
import java.lang.*;
import java.util.*;
import java.io.*;
public class Bookings
{
//3.1 Create an object for input
Scanner kb = new Scanner(System.in);
private int [][] seat√ = new int[15][20]; √
[2]
//3.2 Generate data for the array
public void generate()
{
for(int i=0; i<15; i++)√
{
for(int j=0; j<20; j++)√
{
seat[i][j] √ = (int)(Math.random()*2) √;
}
}
}
//Set First Seat in Each row to be Booked
public void bookFirstSeat()
{
for(int i=0;i<15; i++)√
{
seat [i][0] = 1; √
{
}
//3.3 Display Array
public void display()
{
for(int i=0 ;i<15; i++)√
{
for(int j=0; j<20; j++)√
{
System.out.printf("%-5d"√,seat[i][j] √);
}
System.out.println();√
}
System.out.println();
}
Page 40 of 43
[6]
[5]
Information Technology
Grade 12
KZN-DoE/Trial Exam 2008
//3.4 Resesrve the seat & determine cost
public void reserve()
{
int row;
do
{
System.out.println("Enter the Row");
row = kb.nextInt();√
row = row - 1;
}
while(row >14 || row<0); √
System.out.println("Enter the number Of Tickets Required!");
int num = kb.nextInt();√
int count=0,j=0; √
while(count<num && j<20) √
{
if(seat[row][j] == 0) √
{
seat[row][j] = 1; √
count++; √
}
j++;√
}
if(count<num) √
{
System.out.println("The Number Of Required Seats Are NOT
Available!"); √
}
else
{
System.out.println("Seats Reserverd!");
}
if(row<8) √
{
System.out.println("The Total Price is R"√+(count*50)) √;
}
else
{
System.out.println("The Total Price is R"+(count*40)) √;
}
}
[15]
Page 41 of 43
Information Technology
//3.5
Grade 12
Number of seats taken
public int taken()
{
int count = 0;
for(int i=0; i<15; i++)√
{
for(int j=0; j<20; j++)
{
if(seat[i][j] == 1) √
{
count ++;√
}
}
}
return count; √
}
//3.6 Most popular row
public int popular()√
{
int sum,high=0√,popular = 0; √
for(int i=0; i<15; i++)√
{
sum=0; √
for(int j=0; j<20; j++)√
{
if(seat[i][j] == 1) √
{
sum++;√
}
if(sum > high) √
{
popular = i + 1; √
high = sum; √
}
}
}
return popular; √
}
KZN-DoE/Trial Exam 2008
[4]
(12÷2=6)
//3.7 Display other details
public void displayAll()
{
System.out.println("The Total number of Seats booked by the public is
"+taken());√
System.out.println("The most popular row is "+popular()√); [2]
}
Page 42 of 43
Information Technology
Grade 12
public static void main(String args[])
{
Bookings obj = new Bookings();
obj.generate();
obj.display();
obj.bookFirstSeat();
obj.reserve();
obj.display();
}
}
Page 43 of 43
KZN-DoE/Trial Exam 2008