4 Papers
4 Papers
[2]
3. Which of the following are not valid Java identifiers? Why? [2]
a. Based on the above declarations is the following assignment statement legal? Explain.
PI = 3.1415926; [2]
b. Based on the above declarations is the following assignment statement legal? Explain.
5. Write a single println statement that will output the following exactly as shown (including line
breaks and quotation). [2]
- Laurent Gasser
6. Which of the following pairs of declarations will cause an error message? Explain. [2]
8. Given the following declarations, what result is stored by each of the following assignment
statements?
1
int iResult, num1 = 17, num2 = 5;
9. Apply 6 bit two’s complement representation to show the binary notation for –7. [2]
10. An 8-bit register is used to represent integers in two’s complement. For example, 00101110
is the representation of 4610. Determine the binary representation and calculate the decimal
value of
11. By drawing an appropriate truth table determine whether the following Boolean expressions
are equivalent or not. [3]
a. A ·not B
b. not A + not B ·A
A control system for a conveyor belt uses three sensors to detect the movement of the belt (X),
the presence or absence of items on the belt (Y) and the press of a stop button by the operator
(Z). Each sensor X, Y and Z will send a 0 or a 1 to a 3-bit register with X as the MSB and Z as
the LSB. Under the conditions corresponding to decimal values of 1, 2 5 and 6, a buzzer will
sound.
2
X Y Z Buzzer
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
b. Now complete this Boolean expression for the conditions under which the buzzer will sound:
[2]
c. Draw the logic diagram for the factory control system [3]
13. Define the word “promotion”, and list 1 example of the “promotion” occurrence. [2]
3
15. Construct the unified modelling language (UML) diagram for the Species object. [4]
SpeciesName=s;
return speciesName.equals(s.getSpeciesName());
16. A taxi firm has twenty different locations (stands) in the town where its taxis can wait for
passengers. Each taxi has an onboard Global Positioning System (GPS) device which provides
the present location of that taxi as two coordinates: latitude (lat) and longitude (long). With this
information, it is possible to calculate the distance to a given destination.
4
(a) State the location of the taxi as a pair of coordinates. [1]
double latitude;
double longitude;
// constructor
(b) Construct a constructor method that takes two double arguments to initialize the latitude and
longitude coordinates of a new Location object. [3]
The distance between location A and location B within the town is approximated by
(c) Construct the distance(Location A, Location B) method, that returns the distance between
two locations. You can use the method sqrt() to calculate the square root. [3]
5
– –
A delivery company uses trains in its operations. It uses an object-oriented program to keep track of
its trains and the parcels that it carries.
The company has many objects in their program; here are some of them.
Object Description
Each Train is made up of RollingStock objects, each of which is either a
Train
Wagon or an Engine.
A RollingStock object can be an Engine (that can pull) or a Wagon (that needs
RollingStock
to be pulled). Each RollingStock has a unique ID number and a weight.
A variety of RollingStock. Each Engine has a maximum weight that it
Engine
can pull.
Wagon A variety of RollingStock. Each Wagon has a maximum cargo weight.
Each Parcel is tagged with a tracking number, the addresses from where it came
Parcel
(origin) and to where it is going (destination) and its weight.
The code on the following pages implements the Train class used in this program.
(Option D continued)
(Option D continued)
(b) Outline the advantages of polymorphism, using the RollingStock class as an example. [3]
(c) Construct a unified modelling language (UML) diagram of the Train class. [3]
(d) Construct a method getNumberOfWagons(), part of the Train class, that returns the
number of wagons currently coupled to the train. [2]
(e) Construct the removeWagon() method that will remove one wagon from a train and
return the removed object. Include appropriate error checking. [5]
(Option D continued)
(b) Describe two ways in which programming by a team differs from programming by an
individual working alone. [4]
The following code implements the Parcel class used in the delivery company’s program.
The origin and destination addresses are stored in a Parcel object as simple strings. However,
addresses are complex and there are a lot of different pieces of information that may or may not
be present such as a first name or a business name, in addition to house number, street name,
city and country.
It has been decided to create a new Address class to handle this information.
(c) State the appropriate data type to be used in the Address class to store
(d) Identify the changes to the Parcel class that will be needed to make use of the new
Address class. [3]
(e) Outline how these two new classes can be created with minimal duplication of code. [3]
(Option D continued)
(i) Draw the mEngines array after the code fragment has been executed. [2]
(ii) State the value of mEngineCount after the code fragment has been executed. [1]
(iii) Draw the mWagons array after both the code fragment above and the code fragment
below have been executed. [2]
Wagon F = A.removeWagon();
F = A.removeWagon();
A.addWagon(new Wagon(214));
The parcels loaded into a wagon cannot weigh more than the capacity of the wagon. A train’s
engines must have enough combined power to pull the loaded wagons. The company needs to
be able to check that these requirements are being met.
(b) Construct the getWeight() method in the Wagon class that returns the total combined
weight of the parcels currently in the wagon and the wagon itself. [4]
(c) Construct the getWeight() method in the Train class that returns the total combined
weight of all the parcels, engines and wagons in a train. [4]
(d) Explain why having a getWeight() method in both the Train and Wagon classes
does not cause a compiler error, even though the Train class does not inherit from the
RollingStock class. [2]
End of Option D
––
SECTION A
1. Identify two features that need to be considered when planning a new computing system for
an organization. [2]
3. Describe one advantage and one disadvantage of using observations to gather information when
planning a new system. [4]
4. Outline one usability issue associated with the design of mobile devices. [2]
6. Outline, with an example, one benefit of using computer-aided design (CAD) applications. [2]
SECTION B
(a) Represent, as a single logical expression, the conditions that cause Harry to be tired. [3]
(b) Construct the truth table to show when Harry is tired. [4]
A professor notices that students are generally very tired and decides to investigate the
relationship of tiredness with Work, Hunger and Sun.
Consider the following truth table which shows the conditions for Tired based on Work,
Hunger and Sun.
W H S T
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
(Question continued)
The conditions for one of the students to be tired can be expressed in the following array,
TIRED, where the index is equivalent to the combination of W, H and S in the truth table.
TIRED
[0] [1] [2] [3] [4] [5] [6] [7]
0 0 1 0 0 0 1 1
(c) Identify a relationship between the value of S and the index of the array TIRED. [1]
(d) Construct an algorithm, TEST, in pseudocode, to output the conditions W, H and S from
the array TIRED for a student who is tired. [4]
A collection, STUDENT, is used to hold the name and the array TIRED for each student.
(e) Outline the way in which your algorithm could be used to output the names of all those
students who are tired due to Work and Hunger. [3]
9. An international organization has offices located across several countries. For some of
its activities, for example human resource management, it has been decided to adopt a
“Software-as-a-Service” (SaaS) solution in order to keep the running costs low.
10. The faceplate of a car stereo has six buttons for selecting one of six preferred radio stations.
As part of the internal representation of a microprocessor there is an array with six positions,
carrying the information about the radio frequencies, as follows.
Radio
[0] [1] [2] [3] [4] [5]
100.4 88.7 90.2 104.5 93.8 106.2
(b) Outline how a numerical frequency could be stored in a fixed-length string. [2]
A display in the faceplate shows the name and frequency of the selected radio station. The name
is automatically captured when storing a preference.
(d) Outline how a collection of objects could be used to store the name and frequency data in
the radio. [2]
Section A
1. Outline what is meant by prototyping. [2]
system.
(a) State one advantage of using the direct changeover method. [2]
(b) State one disadvantage of using the direct changeover method. [2]
(a) Calculate and then state the binary notation for −1510. [2]
(b) Explain why an overflow error goes undetected after the following calculation is performed:
4. By drawing an appropriate truth table determine whether the following Boolean expressions are
if (n>0) {
System.out.println(a);
charOut(b,a,n-1);
System.out.println(b);
Joanna 16
9. Identify an abstract data type that will suit the requirements of the following tasks:
(b) processing data records in the order in which they are input [1]
-2-
Section B
10. Two of the most common computer operations are sorting and searching.
(c) State one example of internal sort method and state its efficiency in BigO notation. [2]
(d) State one example of search method and state its efficiency in BigO notation. [2]
(e) Sorts are time consuming and it may be a good policy to avoid them where possible. Explain
11. An application is running on a computer. The main program calls up a subprogram. When the
(a) Explain how a stack would be used to ensure that the correct sequence of instructions are
followed. Reference should be made to the use of the program counter. [3]
(b) Explain why compilers convert mathematical expressions from infix into postfix notation. [2]
(d) With the help of a diagram, explain how a stack would be used in the evaluation of the postfix
s[r] = 0;
(a) Identify any logical errors and suggest the modifications required for this method to function
correctly. [2]
(c) Construct the method which sums the columns of data. [4]
An algorithm is required which will accept the array, data, as a parameter and calculate the average
(arithmetic mean) of each row and output these with the row number. Any elements for which the
data value is 0 should not be included in the calculation of the average for each row.
Thus, for the last row of the above data, the average to be output would be
(4 + 5 + 6) / 3 = 5.0 .
(e) In the method sumRows(int[][] data, int[] s) the arrays are passed as objects (by reference).
Explain the consequences of this when compared to passing a primitive (e.g. int) as a parameter. [2]