Define bioinformatics and give an example of the data used in medical research.
Outline one feature of fuzzy logic which makes it suitable for medical diagnosis.
Full details of the customers are stored as objects of the Customer class. This class is partially shown below:
public class Customer
{
private String memberId;
private String email; //email address (assume only 1 per customer)
public Customer(String a, String b)
{
memberId = a;
email = b;
}
public String getMemberId()
{
return memberId;
}
public String getEmail()
{
return email;
}
}
The objects can be accessed through the linked list allCustomers
which is declared in the main (driver) class as follows:
LinkedList<Customer> allCustomers = new LinkedList<Customer>()
Outline why a linked list structure has been chosen for allCustomers
.
Construct the method goldMails()
that will return an ArrayList
containing the email addresses of all current “Gold” members. You should make use of any previously defined methods.
A game for very young children is played on a board, which is represented by a 4 × 4 square. The game requires two players The aim of the game is to be the first player to reach HOME which is the bottom right square. The players take turns to move between squares. Players can move to an adjacent square which, from their current position, is: - vertically down
List the possible squares to which player A is able to move.
For each of the moves that player A could now take, suggest and justify the best move that player B could then take.
Outline one way of representing player A and player B, and their positions, in memory.
Using your structure from part (i), state the current positions of player A and player B, as shown in the diagram in part (b).
Using your answer to part (i), outline how each possible move from the player's current position could be identified.
Suggest how a best move could be selected from the possible moves.
Outline the effect that changing to a much larger board would have on running the game on a computer.
The management of the company will launch a new scheme to give every 50th car driver and every 60th motorcyclist a free coffee voucher. The code for printing this voucher has already been created and is activated by calling the static method Vouchers.printCoffeeVoucher()
.
AgetKind()
method has already been added to the Vehicle
class, which returns a char
value indicating whether it is a car (c
) or a motorbike (m
).
One test performed on the finished code was defined as follows:
Describe, without writing code, any changes required to the addVehicle
method and the ParkingArea
class to make the new voucher scheme work.
Identify three other tests you might perform on the completed code to prove that it functions correctly.
The removeVehicle
method of the ParkingArea
class searches in the array for a Vehicle
object with a specified registration plate, then removes it by setting that array index to null
.
The method returns a reference to the Vehicle
object that has been removed from the array, or null
if no matching registration plate was found.
Construct the removeVehicle
method.
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 | | :--- | :--- | | Train | Each Train is made up of RollingStock objects, each of which is either a Wagon or an Engine. | | RollingStock | A RollingStock object can be an Engine (that can pull) or a Wagon (that needs to be pulled). Each RollingStock has a unique ID number and a weight. | | Engine | A variety of RollingStock. Each Engine has a maximum weight that it can pull. | | Wagon | A variety of RollingStock. Each Wagon has a maximum cargo weight. | | Parcel | Each Parcel is tagged with a tracking number, the addresses from where it came (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.
Define the function of a constructor.
Outline the advantages of polymorphism, using the RollingStock class as an example.
Construct a unified modelling language (UML) diagram of the Train class.
Construct a method getNumberOfWagons(), part of the Train class, that returns the number of wagons currently coupled to the train.
Construct the removeWagon() method that will remove one wagon from a train and return the removed object. Include appropriate error checking.
Consider the following recursive method.
**public void** recursionEx(**int** x)
{
**if**(x != 0)
{
System.out.println(x);
recursionEx(x - 1);
System.out.println(x);
}
}
Identify two essential features of a recursive algorithm.
Copy and complete the following table to show the output when the method is called by: recursionEx(3)
;
Explain what would happen if the method was called by recursionEx(-3)
.
Identify three features which should be included in either program code or UML diagrams to help programmers understand and modify programs in the future.
A self-driving car relies on a series of lasers and cameras that combine with high definition maps to give a three-dimensional (3D) view of the environment. Rules are programmed into the system so that the car drives at an optimum speed, keeps a safe distance from any vehicle in front, uses fuel economically and follows the traffic regulations.
Outline the need for high definition maps held in memory.
Outline how analysing successive 3D images in memory helps the car to drive safely.
Outline the time and memory needs of 3D visualization in this situation.
Discuss the social implications of self-driving cars.
A generic Event
class is defined as follows:
class Event
{
private String eventID;
private int numberOfRaces;
private Race[] races;
private Race finals;
public Event(String ID, int numberOfRaces)
{
eventID = ID;
races = new Race[numberOfRaces];
for(int i = 0; i < numberOfRaces; i++)
{
races[i] = new Race();
}
finals = new Race();
}
public void addSwimmers()
{
// fills the qualifying heats with swimmers
}
public void fillFinals()
{
// fills the finals race with the best 8 from the qualifying heats
}
// more methods()
}
The Event class above assumes that the event has more than 8 swimmers and requires qualifying heats. However, an event with less than 9 swimmers has no qualifying heats, so the original Event class was inherited by a new class FinalsOnlyEvent.
The same method identifier addSwimmers
is used in both classes Race
and Event
.
Explain why this does not cause a conflict.
Outline two advantages of the OOP feature “inheritance”.
Outline how method overriding can help to create the new class FinalsOnlyEvent
.
The array line
in POSline
is now replaced by a singly linked list
of CartNode
objects. The class CartNode
has been defined as follows.
public class CartNode
{
private Cart myCart;
private CartNode next;
public CartNode(Cart aCart)
{
this.myCart = aCart;
this.next = null;
}
public Cart getCart(){ return this.myCart; }
public CartNode getNext(){ return this.next; }
public void setNext(CartNode nextNode)
{
this.next = nextNode;
}
}
The class POSlist
has been implemented with the standard list methods addLast
and removeFirst
that act on list
.
A method leaveList(int n)
is required in the class POSlist
, similar to the method leaveLine(int n)
that was added to the class POSline
.
Define the term object reference.
Using object references, construct the method public Cart removeFirst()
that removes the first CartNode
object from list
. The method must return the Cart
object in that node or null
if list
is empty.
Sketch the linked list list
after running the following code fragment where cart1, cart2, cart3, cart4
andcart5
have been instantiated as objects of the class Cart
.
POSlist queueList = new POSlist()
queueList.addLast(cart2);
queueList.addLast(cart1);
queueList.addLast(cart4);
queueList.removeFirst();
queueList.addLast(cart5);
queueList.addLast(cart3);
queueList.removeFirst();
Outline one feature of the abstract data structure queue that makes it unsuitable to implement customers waiting in line.
Using object references, construct the method public Cart leaveList(int n)
that removes the nth CartNode
object from list
. The method must return the Cart
object in that node.
You may assume that the nth CartNode
object exists in the list.
You may use any method declared or developed.
Explain the importance of using coding style and naming conventions when programming.
An airport uses an object-oriented program to keep track of arrivals and departures of planes. There are many objects in this system and some are listed below.
The code below outlines the Arrival
class used in this program.
public class Flight
{ private String id;
public String getId() {return this.id;}
// ... more variables, accessor and mutator methods
}
**
public class** Arrival
{ private Flight myFlight;
private String sta; // Scheduled Time of Arrival ('hh:mm')
private int runway;
private String gate;
private int delay;
private boolean landed;
public Arrival(Flight myFlight, String sta)
{ **this.**myFlight = myFlight;
**this.**sta = sta;
**this.**runway = 0;
**this.**gate = null;
**this.**delay = 0;
**this.**landed = false;
}
public void addDelay(int newDelay)
{ **this.**delay = newDelay;
}
public String getETA()
{ // calculates the Estimated Time of Arrival (ETA) of the flight
// by adding the delay to the sta and returning the result as a
// String ('hh:mm')
}
public int compareWith(String flightID)
{ if (myFlight.getID().equals(flightID)) { return 0; }
else { return 1; }
}
public int compareWith(Arrival anotherArrival)
{ // missing code
}
// ... plus accessor and mutator methods
}
The code below outlines part of the FlightManagement
class used in this program.
For the purposes of this exam only arriving flights are being considered.
public class FlightManagement
{
private Arrival[] inbound; // array of inbound airplanes
private int last = -1; // index of last used entry
public FlightManagement()
{ inbound = new Arrival[200];
}
public void add(Arrival newArrival)
{ // missing code that adds the newArrival to the array inbound
// sorted by ETA, and updates last
}
private int search (String flightID)
{ // missing code that searches the array inbound and
// returns the index of the Arrival object with flightID
}
public Arrival remove(String flightID)
{ Arrival result;
int index = search(flightID);
result = inbound[index];
while (index < last)
{ inbound[index] = inbound[index + 1];
index++;
}
last--;
return result;
}
// ... many more methods
}
The method search
in the FlightManagement
class searches the array inbound
and returns the index of the Arrival
object with the given flightID
.
Outline the general nature of an object.
Describe two disadvantages of using Object Oriented Programming (OOP).
Outline one advantage of using modularity in program development.
State the relationship between the Flight
object and the Arrival
object.
Construct a UML diagram to represent theArrival
object.
Construct the method search
implementing a linear search. Use the first compareWith()
method in the Arrival
object.
You may assume that an Arrival
object with the given flightID
exists in the array inbound
.
Outline one advantage of using a binary search.
Outline one disadvantage of using a binary search.