Tuesday, 15 January 2013

java - The type ArrayGSackIterable must implement the inherited abstract method GSackIterableADT.remove() -



java - The type ArrayGSackIterable<T> must implement the inherited abstract method GSackIterableADT<T>.remove() -

this illustration run in our java class today no problem when added files new project having next error. can please tell me if have added files wrongly or maybe professor using different version of files? can allow me know what's reason error , how prepare it?

the code each of file following: arraygsackiterable.java: import java.util.iterator;

public class arraygsackiterable<t> extends arraygsack<t> implements gsackiterableadt<t> { public iterator<t> iterator() { homecoming new arraygsackiterator<t>(items, numitems); } }

and arraygsackiterator.java:

import java.util.iterator; import java.util.nosuchelementexception; public class arraygsackiterator<e> implements iterator<e> { private e[] items; private int numitems, curr; public arraygsackiterator(e[] gsackitems, int num) { items = gsackitems; numitems = num; } public boolean hasnext() { homecoming curr < numitems; } public e next() { if (!hasnext()) throw new nosuchelementexception(); homecoming items[curr++]; } public void remove() { } }

and gsackiterableadt.java:

import java.util.iterator; import java.util.nosuchelementexception; public interface gsackiterableadt<t> extends iterable<t> { void add(t item); t remove() throws nosuchelementexception; boolean isempty(); iterator<t> iterator(); }

update: apparently had add together these 2 files .zip file. gsackadt.java:

import java.util.nosuchelementexception; public interface gsackadt<t> { void add(t item); t remove() throws nosuchelementexception; boolean isempty(); }

arraygsack.java:

import java.util.nosuchelementexception; public class arraygsack<t> implements gsackadt<t> { // internal storage , accounting members protected t[] items; protected int numitems; private static final int init_size = 100; public arraygsack() { items = (t[]) new object[init_size]; numitems = 0; } public void add(t item) { if (numitems == items.length) expandstorage(); items[numitems++] = item; } public t remove() throws nosuchelementexception { if (numitems < 1) throw new nosuchelementexception(); homecoming items[numitems--]; } public boolean isempty() { homecoming numitems == 0; } // internal method handle capacity issues private void expandstorage() { t[] olditems = items; items = (t[]) new object[2 * items.length]; (int = 0; < olditems.length; i++) items[i] = olditems[i]; } }

your code complaining unimplemented method remove interface gsackiterableadt. professor might have done either of these create run:

deleted remove method gsackiterableadt interface marked arraygsackiterable abstract class

java eclipse iterator iterable

No comments:

Post a Comment