2013-04-12 2 views
0

Я получаю 2, не могу найти ошибки символов, и это, похоже, не является результатом пути к классу. У меня также возникает проблема с получением моего метода .add из кода listinterface.java для работы в моем pex6.java. Я не знаю, связано ли это с тем, что im, использующий целое число для типа и метода add, пусто, но я не уверен. Iv'e работал с java уже около 6 месяцев, поэтому я все еще очень новичок в этом. Дайте мне знать, если что-то не хватает.Наличие не может найти ошибку символа и другое

public interface ListInterface<T> 
{ 


/** 
* Should return the number of elements contained within this list: 
*/`enter code here` 
int size(); 


/** 
* Should return true if this list contains a copy of the given object: 
* 
* Comparisons should be performed by calling the equals(...) method of 
* each element, passing the given object as an argument 
*/ 
boolean contains (T theObject); 


/** 
* Should remove the first element found within this list that exists as a 
* copy of the given object and return true if such an element was found: 
*/ 
boolean remove (T theObject); 


/** 
* Should return a reference to the first element found within this list 
* that exists as a copy of the given object or null if no such element was 
* found: 
*/ 
Object get (T element); 


/** 
* Should return a nicely formatted string representation of this list: 
*/ 
String toString(); 


/** 
* Should print the contents of this list to the screen: 
*/ 
void writeLinkedList(); 


/** 
* Should initialize this list for iteration (use of the getNext() method): 
*/ 
void reset(); 


/** 
* Should return a reference to the element located at the iterator's 
* current position and increment the iterator: 
* 
* If the iterator is currently pointing to the last element in this list, 
* the iterator should be reset to point to the first element in this list. 
* 
* @Preconditions: 
*  This list is not empty. 
*  This list has been reset. 
*  This list has not been modified since the last reset. 
*/ 
    T getNext(); 


/** 
* Should insert the given object onto the front of this list: 
*/ 
void add (T theObject); 

} 



public class PEX6 
{ 
public static void main (String[] theArgs) 
    { 
     ListInterface<String> list = new RefList<T>(); 


      for (int i = 1; i <= 20; i++); 
       { 
        int Random = ((int) (Math.random() * 4)); 
        list.add(new Integer(Random)); 

        list.writeLinkedList(); 
       } 
    } 
private static int CountValue(ListInterface<T> theList,int theValue) 
    { 
     theList.clear(); 
     Integer nFound = 20; 


     return nFound; 
    } 

} 

Ошибка:

C:\Users\Linville\Documents\Assignment 6\PEX6.java:16: error: cannot find symbol 
    private static int CountValue(ListInterface<T> theList,int theValue) 
               ^
    symbol: class T 
    location: class PEX6 
C:\Users\Linville\Documents\Assignment 6\PEX6.java:5: error: cannot find symbol 
      ListInterface<String> list = new RefList<T>(); 
                ^
    symbol: class T 
    location: class PEX6 
C:\Users\Linville\Documents\Assignment 6\PEX6.java:11: error: method add in interface ListInterface<T> cannot be applied to given types; 
         list.add(new Integer(Random)); 
          ^
    required: String 
    found: Integer 
    reason: actual argument Integer cannot be converted to String by method invocation conversion 
    where T is a type-variable: 
    T extends Object declared in interface ListInterface 
3 errors 

Tool completed with exit code 1 

Кстати PEX6.java не закончили с помощью любых средств, но я хочу, чтобы идти вперед и получить код компиляции правильно, так что я не в конечном итоге с большим количеством ошибок, чтобы исправить, когда я закончил.

+2

Подсказка: 'ListInterface список = новый RefList ()' должен быть 'ListInterface список = новый RefList ();' –

+0

Что есть вы пишете до сих пор для PEX6.java? – gparyani

+0

Благодарим вас за помощь в методе добавления. Осталось только не найти ошибки символов. Чтобы ответить на вопрос, который вы задаете qparyani, я написал весь код для класса pex6. Я не сделал этого, потому что мне нужно написать метод countvalue. – user1881179

ответ

0

Там не в PEX6 нет T, но вы имеете в виду на него:

ListInterface<String> list = new RefList<T>(); 
             ^here 

private static int CountValue(ListInterface<T> theList,int theValue) 
              ^and here 

Вы должны заменить T либо String или Integer. Невозможно определить, какой из них предназначен: вы объявляете list как ListInterface<String>, а затем переходите к добавлению Integers.

0

Необходимо ввести Тип для T. напр. если вы хотите, чтобы ListInterface быть список строк

private static int CountValue(ListInterface<String> theList,int theValue)

Смежные вопросы