(a)(i)Explain briefly what is meant by the term Encapsulation and
how it is used in the Java programming language.[2 marks ]
(ii)Explain briefly what is meant by the term Polymorphism and how
it is used in the Java programming language.[2 marks ]
(iii)Explain briefly what is meant by the term Inheritance and how
it is used in the Java programming language.[2 marks ]
(iv)Explain briefly the reasons for dividing classes into public and
private
areas.[2 marks ]
(v)Explain briefly the use ofthe keyword import in a Java source code
file.[2 marks ]
(b)(i)Define a public Java class Circle which contains the following:
The co-ordinates of the center of the circle,x and y and the
radius of the
circle r which are of type double and should only be available to
the object
itself;
A constructor function,which takes as parameters values for
the center of
the circle and the radius,and initialises them appropriately. [4 marks
]
(ii)Pi is a famous mathematical constant which is often used in Geometry.Add
to your class a declaration of the constant Pi which should have the
value 3.14
Note that the value of Pi should not be allowed to change.[3 marks
]
(iii)The circumference of a circle is calculated using the formula
2 ×Pi ×radius Add to your class a definition of the public
method Circumference which will
calculate and return the circumference of the circle.[3 marks ]
(c)(i)Using a do /while loop,write a method,called XtoY the signature
of which is given below,which takes two integer parameters,x and y
The method should
return the sum of all the integers in the range x to y Should the
initial value of x
be greater than that of y the method should just return x.
public int XtoY(int x, int y); [5 marks ]
(ii)Using a switch statement,write a method,called AtoI the signature
of which is given below,which takes in a char parameter x and an int
parameter y The
value of y should be returned as 1 if the character passed is a 2
if it is b and -1
otherwise.
public void AtoI(char x, int y); [5 marks ]
|