EECS2030 Lab 2

Due: Sun May 19 before 11:59PM

Introduction

The purpose of this lab is to implement an immutable class having primitive and array fields. The class includes overridden versions of the equals, hashCode, compareTo, and toString methods.

You may, and are encouraged to, work in groups of up to 2 students from the same lab section.

GETTING STARTED

  1. Start eclipse.
  2. Download this project file.
  3. Import the test project by doing the following:
    1. Under the File menu choose Import...
    2. Under General choose Existing Projects into Workspace and press Next
    3. Click the Select archive file radio button, and click the Browse... button. You may have to wait about 10 seconds before the file browser appears.
    4. In the file browser that appears, navigate to your home directory.
    5. Select the file 2030S19Lab2.zip and click OK
    6. Click Finish.
  4. All of the files you need for this test should now appear in eclipse.

Resources

Lab exercise

Implement the class described by this API. You do not have to include javadoc comments.

Polynomials

Polynomials Operations

The class Polynomial will implement the follow operations:

Addition

Polynomials can be added using the associative law of addition (grouping all their terms together into a single sum), possibly followed by reordering, and combining of like terms. For example, if $$\begin{aligned}P&=3x^{2}-2x-2\\Q&=-3x^{2}+3x+8\end{aligned}$$ then $$P+Q=3x^{2}-2x-2-3x^{2}+3x+8$$ which can be simplified to $$P+Q=x+6$$ The degree of $P+Q$ is less than or equal the maximum of $P$ and $Q$ degrees, i.e., $\deg(P+Q) \leq \max(\deg(P),\deg(Q))$.

Subtraction

Similar to addition, subtraction is finding $P - Q$, so in the previous example: $$P-Q=3x^{2}-2x-2 - (-3x^{2}+3x+8)$$ $$P-Q=3x^{2}-2x-2 + 3x^{2}-3x-8)$$ which can be simplified to $$P-Q=6x^{2}-5x-10$$ The degree of $P-Q$ is less than or equal the maximum of $P$ and $Q$ degrees, i.e., $\deg(P-Q) \leq \max(\deg(P),\deg(Q))$.

Multiplication

The product of two polynomials $P$ and $Q$ is a polynomial $P.Q$ with a degree equals the sum of their degrees: $$\deg(P.Q)=\deg(P)+\deg(Q)$$ For example: the degree of $(x^{3}+x)(x^{2}+1) = x^{5}+2x^{3}+x$ is 3 + 2 = 5.

Composition

The composition of the two polynomials $P(x)$ and $Q(x)$ is defined as $P(Q(x))$. For example: let $P=(x^{3}+x)$ and $Q=(x^{2}+1)$, then $$P(Q(x))=$$ $$P(x^{2}+1)=$$ $$(x^{2}+1)^{3}+(x^{2}+1)=$$ $$x^{6}+3x^{4}+4x^{2}+2$$ The degree of the composition of two non-constant polynomials is the product of their degrees: $\deg(P(Q(x)))=\deg(P)\deg(Q)$

Derivative

The derivative of the polynomial $$a_n x^n + a_{n−1} x^{n−1} + \ldots + a_2 x^2 + a_1 x + a_0$$ is the polynomial $$n a_n x^{n−1} + (n − 1)a_{n−1} x^{n−2} + ... + 2 a_2 x + a_1$$

Evaluation

Evaluating a polynomial $P$ for some $x$ value is calculating the function $P(x)$ at the specific value of $x$.


Note: If you cannot complete one or more of the methods, at least make sure that it returns some value of the correct type; this will allow the tester to run, and it will make it much easier to evaluate your code. For example, if you are having difficulty with toString then make sure that the method returns some String (such as the empty string "").
A JUnit tester for your class is available in the project that you downloaded. Note that the tester is not very thorough, and it may not catch all errors that you might make. Also note that passing all of the tests in this tester does not guarantee a good solution (in other words, you should think critically about your implementation for each method).

Submit your work

To submit your work, you need to transfer your Polynomial.java file to a Prism lab computer. You can use a USB stick, a secure FTP program, or a secure copy program to do so.

Once you have transferred your files, log onto a Prism computer and follow the instructions below.

Submit for students NOT working in a group

If you are not working in a group, submit your solution using the submit command. Remember that you first need to find your workspace directory, then you need to find your project directory. In your project directory, your files will be located in the directory src/eecs2030/lab2

  submit 2030 lab2 Polynomial.java
  

Submit for students working in a group

If you are working in a group, create a plain text file named group.txt. You can do this in eclipse using the menu File -> New -> File. Type your login names into the file with each login name on its own line. For example, if the students with login names rey, and finn, worked in a group the contents of group.txt would be:

  rey
  finn

Submit your solution using the submit command. Remember that you first need to find your workspace directory, then you need to find your project directory. In your project directory, your files will be located in the directory src/eecs2030/lab2

  submit 2030 lab2 Polynomial.java group.txt
  

Submit your work from outside the Prism lab

It is possible to submit work from outside the Prism lab, but the process is not trivial; do not attempt to do so at the last minute if the process is new to you. The process for submitting from outside of the Prism lab involves the following steps:

  1. transfer the files from your computer to the undergraduate EECS server red.eecs.yorku.ca
  2. remotely log in to your EECS account
  3. submit your newly transferred files in your remote login session using the instructions for submitting from within the lab
  4. repeat Steps 1 and 3 as required

Windows users will likely need to install additional software first. Mac users have all of the required software as part of MacOS.

Detailed instructions are here.