-
I have no idea?
Well I am in college and my MIS teacher gave me this code to anylize and tell what it is doing...Well I have no idea if you guys can give me step by step definition of what this program is doing I would appreciate.
Code:
{
public Point (int i, int j) {
xCoord = i;
yCoord = j;
}
public void swap() {
int temp = xCoord;
temp=xCoord;
yCoord= temp;
}
public void printIt() {
System.out.printIn("X coordinate = " + xCoord);
System.out.printIn("Y coordinate = " + yCoord);
}
private int xCoord; //X Coordinate
private int yCoord; //Y Coordinate
}
Public Point () {
xCoord = 0;
yCoord = 0;
}
I would really appreciate if you can tell me each step
Thanks very much in advance.
-
Code:
class testPoint
{
// Just a test class.
public static void main(String args[])
{
Point pt = new Point(1, 2);
pt.swap();
pt.printIt();
}
}
class Point
{
// Property variables.
private int xCoord; //X Coordinate
private int yCoord; //Y Coordinate
/*
Constructor (default).
This is a fairly pointless - it has no accessor
functions to set the properties.
*/
public Point ()
{
xCoord = 0;
yCoord = 0;
}
// Overridden constructor.
public Point (int i, int j)
{
xCoord = i;
yCoord = j;
}
/*
This does NOT swap the values - it
actually gives them both the same.
*/
public void swap()
{
int temp = xCoord;
// The following line is pointless - it's initialised above.
temp=xCoord;
yCoord= temp;
/*
This is how you'd want to swap the values.
int temp = xCoord;
xCoord = yCoord;
yCoord = temp;
*/
}
// This just outputs the values to the system output stream.
public void printIt()
{
// Note - your code printIn & not println.
System.out.println("X coordinate = " + xCoord);
System.out.println("Y coordinate = " + yCoord);
}
}
-
A pointless point :rolleyes: