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;
* height range.
*/
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.
*
......@@ -16,7 +18,8 @@ class CoordinateIterator implements Iterator<Coordinate> {
* @param height The height of the coordinate range.
*/
public CoordinateIterator(int width, int height) {
// TODO: à compléter
this.width = width ;
this.height = height ;
}
/**
......@@ -26,8 +29,7 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/
@Override
public boolean hasNext() {
// TODO: à compléter
return false;
return current.y()<height;
}
/**
......@@ -38,7 +40,17 @@ class CoordinateIterator implements Iterator<Coordinate> {
*/
@Override
public Coordinate next() {
// TODO: à compléter
return null;
if (!hasNext()) throw new NoSuchElementException();
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