Results 1 to 3 of 3

Thread: I have no idea?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    21

    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.

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    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.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width