Question

In: Computer Science

Task 4 The class Polynomials is a collection of polynomials of either implementation stored in an...

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 ( )
{ … }
}

Solutions

Expert 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:

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


Related Solutions

The class Polynomials is a collection of polynomials of either implementation stored in an instance of...
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 ( ) { … } (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) { … }...
Task : (Please Answer in C#) Class Polynomials The class Polynomials is a collection of polynomials...
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) {...
Task 2 (1 mark) Transformation of data stored in the relational tables into data stored in...
Task 2 (1 mark) Transformation of data stored in the relational tables into data stored in BSON collection.
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that...
Task 1: [10 Marks] Write a function “reverse” in your queue class (linked list implementation) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue.
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either fiction or nonfiction. Forty percent of the books are fiction and 65% are paperbacks, Also, 25% of the fiction books are hardcover. Now, a book is selected at random. a. What is the probability that it is a paperback?
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either fiction or nonfiction. Forty percent of the books are fiction and 65% are paperbacks, Also, 25% of the fiction books are hardcover. Now, a book is selected at random. a. What is the probability that it is a paperback? b. What is the probability that it is a paperback, given that it is a fiction? c. What is the probability it is a nonfiction,...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either fiction or nonfiction. Forty percent of the books are fiction and 65% are paperbacks, Also, 25% of the fiction books are hardcover. Now, a book is selected at random. a. What is the probability that it is a paperback? b. What is the probability that it is a paperback, given that it is a fiction? c. What is the probability it is a nonfiction,...
A negative Rational could either be represented by a negative value stored in __numerator or a...
A negative Rational could either be represented by a negative value stored in __numerator or a negative value stored in __denominator. If negative values are stored in both, the reduce() method that is provided for you will make them both positive. If a Rational happens to reduce to a whole number, it will still be saved in Rational form. In other words, if the result of an add() call creates a fraction 6/2, it should reduce to 3/1 but will...
Excess food is stored in our body either in the form of carbohydrates (in the muscles...
Excess food is stored in our body either in the form of carbohydrates (in the muscles and liver) or as fat (adipose tissue). When our body needs additional energy it uses the carbohydrate source first as a source of “quick” energy, then the fat. Why do you think carbohydrates are used as a source of quick energy rather than fat?
Complete the implementation of the Die class. Note that the Die class uses an array to...
Complete the implementation of the Die class. Note that the Die class uses an array to represent the faces of a die. You need to complete the no-argument constructor and the two methods compareTo and equals. Code: import java.util.Arrays; import java.util.Objects; import java.util.Random; /* * NOTE TO STUDENTS: * The constructor that you need to complete can be found on line 47. * * The two methods you need to complete can be found at the end of this file....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT