创建项目并将其添加到列表 JAVA
Creating and adding items to list 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.
}
我觉得我没有正确启动列表,因为我无法调用 insert class.
中的列表
字符串将由已经是字符串的多项式组成。
您应该将您的列表作为您的 Polynomial
class 的一个属性,以便您以后可以向其中添加项目。
public class Polynomial {
private List<Term> list;
public Polynomial() {
this.list = new ArrayList<> ();
}
public void insert ( int coeff , int expo ) {
this.list.add(...);
}
我正在尝试创建字符串并将其添加到列表中
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.
}
我觉得我没有正确启动列表,因为我无法调用 insert class.
中的列表字符串将由已经是字符串的多项式组成。
您应该将您的列表作为您的 Polynomial
class 的一个属性,以便您以后可以向其中添加项目。
public class Polynomial {
private List<Term> list;
public Polynomial() {
this.list = new ArrayList<> ();
}
public void insert ( int coeff , int expo ) {
this.list.add(...);
}