August 1999
JP219 : JAVA PROGRAMMING

QUESTION 2

Total Marks: 20 Marks

Click here to access other questions

SUGGESTED SOLUTIONS
Solutions and allocated marks are indicated in green.
Return to
Question 2

(a) One of the key features of an Object Oriented programming language is the ability to design abstract data types. Explain what is meant by an abstract data type. [3]

 

An abstract data type is:
  • A non aggregate data type;
  • With utility operations which operate on that data type;
  • And a strong association between the data and the operations which act upon it.

 

(b) A Java class consists of member variables and methods. Explain, with reference to your definition of an abstract data types, what is meant by the terms

(i) member variable

(ii) method

 

 

[1]

[1]

(i) Member variables are the data held in the class.

(ii) Methods are the operations, or functions, which operate on them.

 

(c) List 3 primitive data types in the Java programming language. [3]
Any 3 of :
  • boolean
  • char
  • byte
  • short
  • int
  • long
  • double
  • float

 

(d) A computer screen is displayed by coloring in a set of pixels (picture elements). Each pixel can be characterized by an x coordinate and a y coordinate.

(i) Define a class, called Pixel, which represents this idea.

(ii) The resolution of a VGA screen is 256 pixels by 256 pixels, giving a total of 65536 pixels. Define a class, VGA_Screen, which contains an array of pixels called MyScreen which is sufficiently large enough to represent the VGA screen.

(iii) Write a main method, which is a member of your VGA_Screen class. Using two nested for loops, the method should initializes the values of the x and y values of each pixel in the array MyScreen, such that each pixel is given a unique coordinate on the screen.

 

 

[3]

[3]



[6]

(i) a sample definition of Point follows:

public class Point{
   int x;
   int y;
}

 

(ii) A sample definition of VGA_Screen follows :

public class VGA_Screen {
   Pixel MyScreen[65535];
}

 

(iii) A sample definition of the main function follows:

public static void main ( ){
   int elem = 0;
   for (int a = 0; a<=255; a++) {
     for (int b=0; b<=255; b++) {
          MyScreen[elem].x=a;
          MyScreen[elem].y=b;
          elem++;
     }
   }
}