/**
 * ParameterPassingExample -- demonstrates pass-by-value parameter passing
 *                            scheme used in Java
 * Author:  Patrick G. Votruba (modified from example by Rebecca Hasti)
 * Date:  4 October 2001, updated 20 February 2002
 */

public class ParameterPassingExample  {

	public static void main (String [] args) {
		double x = 4.5, y = 7.9, x1 = 3.2, y1 = 8.1;
		Point p1, p2, p3, p4;
		p1 = new Point(x1, y1);
		p2 = new Point(y, x);
		p3 = new Point(5.1, -6.7);
		p1.setY(x);
		x1 = area(p1, p2);
		y1 = doStuff(p3, new Point(1.2, 2.5), x, y);

		System.out.println("x1 = " + x1);
		System.out.println("y1 = " + y1);
		System.out.println("p1.getX() = " + p1.getX());
	} // end main()

	/**
	 * does some dumb stuff then always returns the x-coordinate of p2
	 * (does not always return 5.0 as previously documented -- updated 7/2/02)
	 * @param p1 first Point
	 * @param p2 second Point
	 * @param x illustrates pass by value
	 * @param y illustrates pass by value
	 * @return the x value of p1
	 */
	public static double doStuff (Point p1, Point p2, double x, double y) {
		x = 0.0;
		y = 0.0;
		p1.setX(5);
		p1 = p2;
		return p1.getX();
	} // end doStuff

	/**
	 * Given two Points, computes the area of a rectangle where
	 * the 2 points are opposite corners of the rectangle
	 * @param p1 first Point
	 * @param p2 second Point
	 * @return area of rectangle corresponding to p1 and p2
	 */
	public static double area (Point p1, Point p2) {
		double x1, x2, y1, y2;
		x1 = p1.getX();
		y1 = p1.getY();
		x2 = p2.getX();
		y2 = p2.getY();
		return Math.abs(x1 - x2) * Math.abs(y1 - y2);
	} // end area

	/**
	 * returns a Point where x and y are reversed from the given Point
	 * @param p the Point
	 * @return a mirror image of p
	 */
	public static Point inverse (Point p) {
		return new Point(p.getY(), p.getX());
	} // end inverse

	/*******
			PROGRAM OUTPUT
			--------------
			x1 = 0.0
			y1 = 1.2
			p1.getX() = 3.2
	********/

} // end ParameterPassingExample class
