Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer by yourself only in Java. Don't copy. Thank you. The following rules should be observed throughout the assignment: Each polynomial should be represented

Please answer by yourself only in Java. Don't copy. Thank you.

The following rules should be observed throughout the assignment:

Each polynomial should be represented as a singly-linked list (use the list implementation

covered in the lecture notes).

Each element in the linked list should represent one of the terms in the polynomial.

The data held by each element should be type Double representing the constant for that

term.

For example, the polynomial 6.0x3 - 5.3x + 3.1 would be represented by the linked list

6.0 -> 0.0 ->5.3 ->3.1.

All code implemented in this assignment should be in a class called Homework2. You may use the

data structures and algorithm code from the lecture notes.

a) (1 point) Implement a method called appendTerm:

static void appendTerm(SinglyLinkedList polynomial,

Double coefficient)

This method should append (insert at the end) the value coefficient to polynomial. For

example, appending 3.1 to polynomial already containing 6.0 -> 0.0 -> 5.3 should

result in the value 3.1 being added at the end: 6.0 -> 0.0 -> 5.3 -> 3.1.

b) (2 points) Implement a method called display:

static void display(SinglyLinkedList polynomial)

This method should print the polynomial in proper polynomial format. For example,

displaying polynomial 6.0 -> 0.0 -> 5.3 -> 3.1 should result in 6.0x3 - 5.3x +

3.1 being printed.

c) (2 points) Implement a method called evaluate:

static Double evaluate(SinglyLinkedList polynomial, Double x)

This method should evaluate the polynomial for the given value of x and return the result.

For example, given polynomial 6.0 -> 0.0 -> 5.3 -> 3.1 and x having value 7.0 the

function should return 2024.0 (the result of evaluating 6.0*7.03 - 5.3*7.0 + 3.1).

d) (4 points) Write a program to test the method from parts a c. Your test program should

demonstrate creating, displaying, and evaluating the following polynomials with the given

values for x:

x + 1.0 with x = 1.0

x2 - 1.0 with x = 2.03

-3.0x3 + 0.5x2 - 2.0x with x = 05.0

-0.3125x4 - 9.915x2 - 7.75x - 40.0 with x = 123.45

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions