|
-
Feb 11th, 2003, 11:58 PM
#1
Thread Starter
Junior Member
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.
-
Feb 12th, 2003, 12:42 AM
#2
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);
}
}
Last edited by axion_sa; Feb 12th, 2003 at 12:45 AM.
-
Feb 13th, 2003, 12:31 PM
#3
A pointless point
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|