Skip to content
Snippets Groups Projects
Commit bd8c7028 authored by SAHIN Melis damla's avatar SAHIN Melis damla
Browse files

Compléter la classe CoordinateIterator

parent aefbcb2e
No related branches found
No related tags found
No related merge requests found
Pipeline #38279 failed
...@@ -8,7 +8,9 @@ import java.util.NoSuchElementException; ...@@ -8,7 +8,9 @@ import java.util.NoSuchElementException;
* height range. * height range.
*/ */
class CoordinateIterator implements Iterator<Coordinate> { class CoordinateIterator implements Iterator<Coordinate> {
private final int width ;
private final int height ;
private Coordinate current = new Coordinate(0,0) ;
/** /**
* Creates a new {@link CoordinateIterator} with the specified width and height. * Creates a new {@link CoordinateIterator} with the specified width and height.
* *
...@@ -16,7 +18,8 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -16,7 +18,8 @@ class CoordinateIterator implements Iterator<Coordinate> {
* @param height The height of the coordinate range. * @param height The height of the coordinate range.
*/ */
public CoordinateIterator(int width, int height) { public CoordinateIterator(int width, int height) {
// TODO: à compléter this.width = width ;
this.height = height ;
} }
/** /**
...@@ -26,8 +29,7 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -26,8 +29,7 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/ */
@Override @Override
public boolean hasNext() { public boolean hasNext() {
// TODO: à compléter return current.y()<height;
return false;
} }
/** /**
...@@ -38,7 +40,17 @@ class CoordinateIterator implements Iterator<Coordinate> { ...@@ -38,7 +40,17 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/ */
@Override @Override
public Coordinate next() { public Coordinate next() {
// TODO: à compléter if (!hasNext()) throw new NoSuchElementException();
return null;
Coordinate next = current;
// on crée un méthode update
update();
return next;
}
private void update(){
current = current.right();
if (current.x() == width)
current = new Coordinate(0, current.y()+1);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment