Java代码实现Linked List数据结构

CSCI 1933 Project 2: Implementing Linked Lists Due Date: July 17, 2019 Before Midnight 100 Points

Summary: Project 2 will involve using Linked Lists to perform polynomial arithmetic.

For a review of polynomial arithmetic see: https://www.khanacademy.org/math/algebra/introduction-to-polynomial- expressions/add-subtract-poly-two-var/v/addition-and-subtraction-of-polynomials

A polynomial of degree n has the form𝑎𝑛𝑥𝑛 + 𝑎𝑛−1𝑥𝑛−1 + ⋯ 𝑎2𝑥2 + 𝑎1𝑥 + 𝑎0 where a0, a1, a2, …, an are numeric constants called the coefficients of the polynomial and an ≠ 0. In a polynomial all exponents are positive integers and for simplicity we will assume the coefficients are all integer data types. The degree of the polynomial is determined by the greatest exponent.

A term for a polynomial is a single term. Given the polynomial 5𝑥4 − 7𝑥3 + 3𝑥 + 1 the degree is 4 since it is the largest exponent and the integer coefficients are 5, -7, 0, 3, and 1 where 1 is considered the constant term. The term 5𝑥4 is considered the leading term since contains the largest exponent.

Please note the value of 0 represents the coefficient of the 𝑥2 term.

A term of a polynomial is: −7𝑥3 and the degree of the term is 3 with a coefficient of -7.

Polynomials are always written in standard form which means in descending powers of the exponents. The following polynomial is written in standard form: 5𝑥4 − 7𝑥3 + 3𝑥 + 1.

Part 1: Define the class called Term — 30 Points

This class will define the terms of the polynomial. It should have two attributes, the coefficient and the exponent of the term.

The methods of the class should be:

a) An explicit value constructor

b) Getters and Setters for the two attributes

c) A toString method to output the term: For example the term −7𝑥3 would be output as -7x^3

d) An evaluate method to evaluate the term. For example given the term −7𝑥3 and suppose x has a value of 2 the

evaluate method would return -56.0 .

e) A multiply method that would accept two terms as arguments and return the result of the two terms being

multiplied. The result of the multiplication would be another term.

Part 2: Defining a Polynomial Class — 60 Points

For the Polynomial class you will be utilizing the built-in Java class LinkedList. Include the following import statement:

import java.util.LinkedList;

For all of the methods of the above class see: https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html

For the implementation of the polynomial class would be for each node in a linked list representing the each term of the polynomial. Therefore the attribute of the class would be:

private LinkedList<Term> variable of your choosing; The methods of the Polynomial class should have:

1. A default constructor to create an empty Linked List.

2. A getter method to return the Linked List.

3. An input method where the user will input the polynomial always in standard form. I.e. Leading term followed

by the other terms in descending order of the exponent. Investigate the Scanner class on how to parse an input string. Please note you might have to keep track of the sign of the coefficient depending on your implementation of the input. Examples of input:

a) 5𝑥4−7𝑥3+3𝑥+1

b) −7𝑥3

c) 1

d) 𝑥4−𝑥3+3𝑥

In all of the above the input string is the entire polynomial.

4. Create a method called AddTerm to add nodes to the Linked List. The signature of the method should be:

public void AddTerm(int coefficient, int exponent)

The Linked List being used by the Polynomial class should be a sorted Linked List in descending order based upon the exponent. This means you will have to find the location in the Linked List to insert the term so it is the correct order.

5. Implement an output operation for the Polynomial class. This should be a toString method where the polynomial will be output in standard form.

6. Add an evaluate operation to your Polynomial class that allows the user to enter a value for x and calculates the value of the polynomial for that value.

7. Add an addition operation to your Polynomial class.

8. Add a multiplication operation to your Polynomial class.

Part 3: Writing a driver class — 10 points

Write a class containing the method main so that it tests all of the methods of your Polynomial class. Make sure you have output statement stating what is being tested. It should test:

1. You should have the user input at most two different polynomials based upon the specifications above. Make sure you test for all cases of the polynomial as specified above.

2. Your addition method. In this case you will need two polynomials input by the user.

3. Your multiplication method. In this case you will need two polynomials input by the user.

4. Your evaluate method for a positive integer and a negative integer for any polynomial.

Submitting your finished assignment:

Once you’ve completed Project 2, create a zip file with all of your Java files (.java), including one that implements your main program, and submit it through Canvas.

Working with a partner:

You may work with one partner to complete this assignment (max team size = 2). If you choose to work as a team, please only turn in one copy of your assignment. At the top of your class definition that implements your main program, include in the comments both of your names and student IDs. In doing so, you are attesting to the fact that both of you have contributed substantially to completion of the project and that both of you understand all code that has been implemented.

Some guidelines about how we will grade your project:

To give you a sense for the grade your assignment will receive, here are some examples of what will be required for each grade level:

A-level assignment:

Properly defined Term and Polynomial classes with correctly implemented methods. Main program implemented that correctly receives input from user

Main program that correctly outputs two polynomials.

Correct instantiation/use of the Polynomial class.

Demonstration that the methods of the Polynomial class addition, multiplication, and evaluate work. Good programming style (spacing and comments)

B-level assignment:

Properly defined Term and Polynomial classes with correctly implemented methods. Main program implemented that correctly receives input from user.

Main program implemented that correctly outputs the polynomial.

Correct instantiation/use of the Polynomial class.

Partially working Polynomial class.

C-level assignment:

Properly defined Term and Polynomial classes with correctly implemented methods. Main program implemented that correctly receives input from user

**程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB**

本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！

**E-mail:** [email protected] **微信:**dmxyzl003

如果您使用手机请先保存二维码，微信识别。如果用电脑，直接掏出手机果断扫描。