In: Computer Science
Task 4
The class Polynomials is a collection of polynomials of either
implementation stored in an instance of the
generic library class List.
class Polynomials
{
private List<Polynomial> L;
// Creates an empty list L of polynomials
public Polynomials ( )
{ … } (1 mark)
// Retrieves the polynomial stored at position i in L
public Polynomial Retrieve (int i) (1 mark)
{ … }
// Inserts polynomial p into L
public void Insert (Polynomial p) (1 mark)
{ … }
// Deletes the polynomial at index i
public void Delete (int i) (1 mark)
{ … }
// Returns the number of polynomials in L
public int Size ( )
{ … } (1 mark)
// Prints out the list of polynomials
public void Print ( )
{ … } 
}
Short Summary:
**************Please do upvote to appreciate our time. Thank you!******************
Source Code:
import java.util.ArrayList;
import java.util.List;
/** The class Polynomials is a collection of polynomials of
either implementation stored in an instance of the
generic library class List. **/
class Polynomials
{
   private List<Polynomial> L;
   // Creates an empty list L of polynomials
   public Polynomials ( )
   {
       L=new
ArrayList<>();  
   }
   // Retrieves the polynomial stored at position i in
L
   public Polynomial Retrieve (int i)
   {
       return L.get(i);
   }
   // Inserts polynomial p into L
   public void Insert (Polynomial p)
   {
       L.add(p)   ;
   }
   // Deletes the polynomial at index i
   public void Delete (int i)
   {
       L.remove(i)   ;
   }
   // Returns the number of polynomials in L
   public int Size ( )
   {
       return L.size(); }
   // Prints out the list of polynomials
   public void Print ( )
   {
       for(Polynomial pol:L)
       {
          
System.out.println(pol.toString());  
       }
   }
}
Code Screenshot:


**************Please do upvote to appreciate our time. Thank you!******************