1. Identify two instance variables and two methods from the case below.
An application that manipulates Points on a plane is to be designed using Objected Oriented
Design. In this application, Points must have X and Y coordinates, move on the plane as well as display their current values of X and Y. Points can also determine if they are in the zero position (0,0) with a Boolean answer. [8]
a. Assume the existence of a Java file myClass.java. Explain how Java uses both a compiler and interpreter to achieve its architecture-neutral characteristic. [5]
b. Using an example, explain the implication of using the keyword void in a method declaration
c. Given an Object-Oriented System that manages student records (name, date of birth,[3]
d. gender etc), use examples to differentiate between Class and Object as used in OOP.[4]
import java.util.ArrayList;
public class Points {
private ArrayList<Integer[]> points;
public Points() {
points = new ArrayList<>();
}
public boolean isZeroPosition(int i) {
return points.get(i)[0] == 0 && points.get(i)[1] == 0;
}
public void addPoint(int x, int y) {
points.add(new Integer[]{x, y});
}
public void movePoint(int i, int dx, int dy) {
points.get(i)[0] += dx;
points.get(i)[1] += dy;
}
public void display() {
for (Integer[] point : points) {
System.out.println("X= " + point[0] + " Y= " + point[1]);
}
}
}
public class Student{
//...
}
Student student = new Student();
Comments
Wow. Thank you so much for your kind help.
Leave a comment