0% found this document useful (0 votes)
16 views18 pages

4 Papers

The document consists of a series of programming and computer science questions, covering topics such as Java programming concepts, object-oriented programming, Boolean logic, and system design. It includes tasks like distinguishing between terms, writing code snippets, creating truth tables, and constructing UML diagrams. Additionally, it addresses practical applications in a factory control system and a delivery company's operations.

Uploaded by

vangelgable5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

4 Papers

The document consists of a series of programming and computer science questions, covering topics such as Java programming concepts, object-oriented programming, Boolean logic, and system design. It includes tasks like distinguishing between terms, writing code snippets, creating truth tables, and constructing UML diagrams. Additionally, it addresses practical applications in a factory control system and a delivery company's operations.

Uploaded by

vangelgable5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

1. Distinguish between “Java bytecode” and “machine language”.

[2]

2. Distinguish between “Class” and “Object”. [3]

3. Which of the following are not valid Java identifiers? Why? [2]

a. RESULT b. result c. 1stmonthlytest

d. $100 e. black&write f. problem_1

4. Given the following variable declarations, answer each question.

int count = 0, value, total;

final double PI = 3.14;

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.

total = 100.00; [2]

5. Write a single println statement that will output the following exactly as shown (including line
breaks and quotation). [2]

“Computers do not solve problems,

they execute solutions”

- Laurent Gasser

6. Which of the following pairs of declarations will cause an error message? Explain. [2]

a. double x=14.7; b. double x = 14.7; c. int x = 14;

int y = x; int y = (int)x; double y = x;

7. What does an “import” statement accomplish? [2]

8. Given the following declarations, what result is stored by each of the following assignment
statements?

1
int iResult, num1 = 17, num2 = 5;

double fResult, val1 = 12.0, val2 = 4.63;

a. iResult = num1 / num2; [1]

b. fResult = num1 / num2; [1]

c. fResult = val1 / num2; [1]

d. fResult =(double) num1 / num2; [1]

e. iResult = (int) val2 / num2; [1]

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

a. the largest number that can be stored. [1]

b. the smallest (most negative) number that can be stored. [1]

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

12. The Factory Control System

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.

a. Complete this truth table for this situation: [3]

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]

14. Explain the “Integer” and “int” in Java. [2]

3
15. Construct the unified modelling language (UML) diagram for the Species object. [4]

public class Species{

private String speciesName;

public Species( String s){

SpeciesName=s;

public void setSpeciesName(String s){ speciesName = s; }

public String getSpeciesName(){ return speciesName; }

public String toString(){

return "Species: " + speciesName;

public boolean equals(Species 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]

An object of class type Location defines the coordinates of a location.

public class Location {

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
– – 

Option D — Object-oriented programming

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 continues on the following page)


––

(Option D continued)

public class Train


{
private Engine[] mEngines;
private Wagon[] mWagons;
private int mEngineCount;
private int mWagonCount;
private int mTrainNumber;
private double mWeight; // Total weight in kilograms
public Train(int number)
{
mTrainNumber = number;
mEngines = new Engine[6]; // The train can have up to 6 engines
mEngineCount = 0;
mWagons = new Wagon[100]; // The train can have up to 100 wagons
mWagonCount = 0;
mWeight = 0;
}
public void addEngine( Engine newEngine )
{
mEngines[mEngineCount] = newEngine;
mEngineCount++;
}
public Engine removeEngine()
{
mEngineCount--;
return mEngines[mEngineCount];
}
public void addWagon( Wagon newWagon )
{
mWagons[mWagonCount] = newWagon;
mWagonCount++;
}
public Wagon removeWagon()
{// Code to be written
}
public double getWeight()
{// Code to be written
}
...
}

public class RollingStock


{
private int mIDNumber;
private double mWeight;
public RollingStock(int ID, double weight)
{
mIDNumber = ID;
mWeight = weight; // Weight is in kilograms
}
// Accessor methods
public double getWeight() { return mWeight; }
public int getID() { return mIDNumber; }
...
// Other methods
...
}
(Option D continues on the following page)
–3– 

(Option D continued)

public class Engine extends RollingStock


{
private double mPullingWeight; // maximum weight engine can pull
public Engine(int ID)
{
super(ID, 120000); // Engines weigh 120000 kilograms
mPullingWeight = 1400000; // Engines can pull 1400000 kilograms
}
// Accessor methods
public double getWeight() { return super.getWeight(); }
...
// Other methods
...
}

public class Wagon extends RollingStock


{
private Parcel[] mParcels;
private int mParcelCount;
public Wagon(int ID)
{
super(ID, 32000); // Empty wagon weighs 32000 kilograms
mParcels = new Parcel[100];
mParcelCount = 0;
}
// Accessor methods
public int getWagonID() { return this.getID(); }
public double getWeight()
{
// Code to be written
}
...
// Other methods
...
}

1. (a) Define the function of a constructor. [2]

(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 continues on the following page)


–4–

(Option D continued)

. (a) Outline one advantage of using standard library collections. [2]

(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.

public class Parcel


{
private int trackingID;
private double weight;
public String destinationAddress;
public String originAddress;
public Parcel(int ID)
{
trackingID = ID;
weight = 0;
}
public void setWeight(double newWeight) { weight = newWeight; }
public double getWeight() { return weight; }
}

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

(i) the street name; [1]

(ii) the building number; [1]

(iii) an indication of whether or not this is a business address. [1]

(d) Identify the changes to the Parcel class that will be needed to make use of the new
Address class. [3]

Separate OriginAddress and DestinationAddress classes will be created. The destination


address may contain special instructions to the delivery person. The origin address contains a
variable that indicates if the parcel was collected from the customer’s house or from the local
post office.

(e) Outline how these two new classes can be created with minimal duplication of code. [3]

(Option D continues on the following page)


–5–

(Option D continued)

3. (a) Consider the following code fragment.

Train A = new Train(123);


Engine B = new Engine(7);
A.addEngine(B);
Wagon C = new Wagon(23);
A.addWagon(C);
Wagon D = new Wagon(66);
A.addWagon(D);
Wagon E = new Wagon(71);
A.addWagon(E);
A.addEngine(new Engine(9));

(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

Answer all questions.

1. Identify two features that need to be considered when planning a new computing system for
an organization. [2]

2. Explain what is meant by beta testing. [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]

5. Distinguish between the use of two types of primary memory. [2]

6. Outline, with an example, one benefit of using computer-aided design (CAD) applications. [2]

7. Outline how a colour can be represented in a computer. [2]


––

SECTION B

Answer all questions.

. Harry is Tired (T) depending on the following three variables:


• Work (W)
• Hunger (H)
• Sun (S).

Harry is tired if:


• he works and he is hungry
• he works and it is not sunny
• he does not work and is not hungry.

(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

(This question continues on the following page)


–– 

(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.

(a) Describe the features of SaaS. [3]

(b) Discuss the limitations of SaaS in relation to security. [6]


–6–

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

(a) State the information at Radio[2]. [1]

(b) Outline how a numerical frequency could be stored in a fixed-length string. [2]

(c) Construct an algorithm, in pseudocode, that calculates the range of frequencies


(ie the difference between the highest and lowest frequencies) of any set of six selected
radio stations. [6]

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]

2. An organization is considering using a direct changeover method to implement a new computer

system.

(a) State one advantage of using the direct changeover method. [2]

(b) State one disadvantage of using the direct changeover method. [2]

3. Applying 7 bit two’s complement representation:

(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:

01111112 + 00000012 . [2]

4. By drawing an appropriate truth table determine whether the following Boolean expressions are

equivalent or not. [4]

5. Describe how the computer carries out a machine instruction. [4]

6. Given the following recursive method.

public static void charOut( char a, char b, int n) {

if (n>0) {

System.out.println(a);

charOut(b,a,n-1);

System.out.println(b);

Determine the output produced by the call charOut('1','2',2).

Show all your working. [4]


-1-

7. Consider the following linked list which is maintained in alphabetical order.

Jean 9 Mario 7 Phoebe 2 Roman 6 Samira 8

With the aid of diagrams, explain how the node

Joanna 16

would be inserted into the linked list. [3]

8. Consider the following binary tree.

Determine the result of the following traversals of the tree:

(a) preorder [1]

(b) postorder [1]

(c) inorder [1]

9. Identify an abstract data type that will suit the requirements of the following tasks:

(a) searching a large set of unordered data [1]

(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.

(a) Explain what is meant by sorting. [2]

(b) Explain what is meant by searching. [2]

(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

how this could be done. [2]

11. An application is running on a computer. The main program calls up a subprogram. When the

subprogram finishes, control is passed back to the main program.

(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]

(c) Convert the infix expression (A + B) /C into postfix. [2]

Stacks can also be used when evaluating arithmetic expressions.

(d) With the help of a diagram, explain how a stack would be used in the evaluation of the postfix

expression AB+ . [3]

12. Consider the following two-dimensional array, data.

The following method was designed to sum the rows of data.

public void sumRows(int[][] data, int[] s){

for (int r = 0; r < 4; r++){

s[r] = 0;

for (int c = 0; c < 4; c++){


-3-

s[r] = s[r] + data[r][c];

(a) Identify any logical errors and suggest the modifications required for this method to function

correctly. [2]

(b) State the BigO efficiency of the method sumRows. [1]

(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 .

(d) Construct the method described above. [11]

(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]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy