1) Is this right?
In java.awt there is a class named Point which represents a point in 2-D space. It has methods getX() and getY().

Below is the definition of a Points class which has a Point[] array as an instance variable. You are to write a method getMaxX() that returns the maximum x coordiniate in the array of Points. You may assume the array is completely filled (no null values). Add your code to the class below.

import java.awt.Point;
public class Points
{
private Point[] points;

/**
* Constructs a collection of points
* @param an arra of Point objects
*/
public Points(Point[] thePoints)
{
points = thePoints;
}

/**
* Gets the maximum x co-ordinate in this collection of points
* @return the maximun x coordinate
*/
public double getMaxX()
{

double number = points.getX();
return number;

}

}

2) What is the error here?
Is is the list? Do I have to define it using list[10]?

public class Error1
{
   /**
    * Prints the elements of the given array one per line
    * @param list the array to print
    */
   public static void printArray(int[] list)
   {
      for (int i = 0; i <= list.length; i++)
      {
         System.out.println(list[i]);
      }
   }
}

3) I don't know how to fix this:

public class Error1B
{
    public static void findEven(int n)
    {
        /**
         * Prints all the even numbers less than the given number
         * n the upper limit for the numbers
         */
        for (int i = 1; i < n; i++)
        {
            if (i % 2 = 0)
            {
                System.out.println(i);
            }
        }
    }
}

Looks like school assignments so I wont explicitly tell you the answers, you need to figure it out on your own.

1. In the getMaxX() method you need to iterate over all the Points and compare each x-coordinate. Have a local variable to keep track of the largest x-coordinate and when you encounter a Point with a larger x-coordinate you store that as the max.

2. Look at this line:

for (int i = 0; i <= list.length; i++)

3. Look at this line:

if (i % 2 = 0)
This article has been dead for over six months. Start a new discussion instead.