In: Computer Science
Task : (Please Answer in C#)
Class Polynomials
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 L;
// Creates an empty list L of polynomials
public Polynomials ( )
{ … }
// Retrieves the polynomial stored at position i in L
public Polynomial Retrieve (int i)
{ … }
// Inserts polynomial p into L
public void Insert (Polynomial p)
{ … }
// Deletes the polynomial at index i
public void Delete (int i)
{ … }
// Returns the number of polynomials in L
public int Size ( )
{ … }
// Prints out the list of polynomials
public void Print ( )
{ … }
}
Solution :
Short Summary:
Implemented all the methods as per the requirement
Attached source code and screenshot
**************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:
Thank you...!