Java Reference
In-Depth Information
//**********************************************************
//**********************************************************
// Program: Pixels
// Reference: Chapter 17
// Topics:
// 1. Objects passed as an arguments
// 2. Methods that return objects
//**********************************************************
//**********************************************************
//******************************************
// Pixel class
//******************************************
class Pixel
{
// Pixel location attributes
private int x;
// x coordinate
private int y;
// y coordinate
// Constructor
public Pixel(int pixX, int pixY)
{
this.x = pixX;
this.y = pixY;
}
// Method to calculate the mid point between two pixels
public static Pixel midPix(Pixel p1, Pixel p2)
{
int midX = (p1.x/2) + (p2.x/2);
int midY = (p1.y/2) + (p2.y/2);
Pixel midOne = new Pixel(midX, midY);
return midOne;
}
// Display the address of a pixel
public void pixLocation()
{
System.out.print("Pixelx:"+this.x + " ");
System.out.print("Pixely:"+this.y + "\n\n");
System.out.flush();
}
}
//******************************************
//******************************************
// Driving class
//******************************************
//******************************************
//
public class Pixels
{
public static void main(String[] args)
Search WWH ::




Custom Search