2015-04-22 5 views
-1

Im пытается создать и добавить строки в списокСоздание и добавление элементов в список JAVA

package the.arraylist.pkgclass; 

import java.util.ArrayList; 

/** 
A class to implement a Polynomial as a list of terms, where each term has 
an integer coefficient and a nonnegative integer exponent 

@author your name 
*/ 
public 
     class Polynomial 
{ 
// instance variable declarations go here 
Term theTerm ; //initializes a term 

/** 
Creates a new Polynomial object with no terms 
*/ 
public 
     Polynomial() 
{ 
    // TO DO: Write constructor body here 

    ArrayList<Term> list1 = new ArrayList<>(); 
} 

/** 
Inserts a new term into its proper place in a Polynomial 

@param coeff the coefficient of the new term 
@param expo the exponent of the new term 
*/ 
public 
     void insert (int coeff , int expo) 
{ 
    // TO DO: write method body here. 
} 

Я не чувствую, что я инициировал список правильно, потому что я не могу назвать в списке в вставка класс.

Строки состоят из полиномов, которые уже являются строками.

+0

Не знаете, что вы подразумеваете под «Строки будут состоять из полиномов, которые уже являются нитями». – Claudio

ответ

1

Вы должны сохранить свой список как атрибут своего класса Polynomial, чтобы впоследствии добавлять в него элементы.

public class Polynomial { 

private List<Term> list; 

public Polynomial() { 
    this.list = new ArrayList<>(); 
} 

public void insert (int coeff , int expo) { 
    this.list.add(...); 
} 
+0

В этом была проблема. Большое спасибо. Сейчас все работает. – dchar028

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