So I have this class of terms
public class Term {
private int coefficient ;
private int exponent ;
public Term(int coefficient, int exponent)
{
this.coefficient = coefficient ;
this.exponent = exponent ;
}
public int getCo()
{
return coefficient ;
}
public int getEx()
{
return exponent ;
}
}
And I have a class called Polynomial that creates an arraylist of type term with a method called delete that isn't working the way I'd like it to and I can't figure out why:
public class Polynomial{
public Polynomial()
{
poly = new ArrayList<>() ;
}
public void delete (int coeff, int expo)
{
for(int i = 0; i < poly.size(); i++)
{
System.out.println("**Delete Loop works") ; //This does not print
if( (poly.get(i).getCo() == coeff) && (poly.get(i).getEx() == expo) )
{
poly.remove(i) ;
removed = true ;
break ;
}
}
}
}
It keeps throwing an exception every time I run the delete method and I'm not sure why?? I am using input from a text file (and the input is working fine), I think it might be going wrong where I use : poly.get(i).getCo() == coeff is that properly written?
Thanks for any help you can provide!
//this does not printit doesn't even print if I write a loop that is always true. It is strange.ArrayListis empty.