/*
 * Code19.java
 * Dan Armendariz
 * Computer Science S-76
 *
 * Demonstrates implications of passing data into methods by value.
 *
 */

class Code19 {

	// define two integer fields
	private static int firstNum;
	private static int secondNum;

	// an object that contains two pieces of data: an int x and an int y
	// The constructor for this class accepts two values that are then
	// inserted into these fields.
	private static class Point {
		public int x;
		public int y;
		
		public Point(int first, int second) {
			x = first;
			y = second;
		}
	}

	// Accepts two integers as parameters and should swap them.
	private static void swap(int x, int y) {
		int temp;
		
		temp = x;
		x = y;
		y = temp;
	}

	// Accepts a Point object and swaps the data in the x and y fields.
	private static void swap(Point a) {
		int temp;
		
		temp = a.x;
		a.x = a.y;
		a.y = temp;
	}

	public static void main(String [] args) {

		// assign some values to our integer fields
		firstNum = 1;
		secondNum = 2;

		// instantiate a new Point object, and provide some data
		Point a = new Point(3, 4);

		// attempt to swap the data in the two integer fields
		System.out.println("firstNum: "+firstNum+", secondNum: "+secondNum);
		swap(firstNum, secondNum);
		System.out.println("firstNum: "+firstNum+", secondNum: "+secondNum);

		// attempt to swap the data in the Point object
		System.out.println("a.x: "+a.x+", a.y: "+a.y);
		swap(a.x, a.y);
		System.out.println("a.x: "+a.x+", a.y: "+a.y);

	}

}
