Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC 191 Lab 3 Arrays Polynomial Math (worth 20 points) Due Date: Wednesday 2/1/2023 at 11:59 PM You will be designing a class that will

CSC 191 Lab 3 Arrays Polynomial Math (worth 20 points) Due Date: Wednesday 2/1/2023 at 11:59 PM You will be designing a class that will represent the concept of a polynomial. Remember that polynomials can have different degrees and each term of the polynomial has coefficients. For example, 53 + 22 + + 6 is a polynomial with degree 3 since the largest term is 3. The number in front of each term is that term's coefficient. Remember the coefficient can be 1, 0 or a negative integer. Create a NetBeans project named FirstnameLastnameLab3 which contains source code file with a public class containing a main method and another class named Polynomial. In the same file, use the code below to start your Polynomial class. Add the following to the Polynomial class: A method named addPoly(Polynomial P1, Polynomial P2) that takes 2 polynomials and returns the polynomial that results from adding the two polynomials together. A method named multiplyPoly(Polynomial P1, Polynomial P2) that takes 2 polynomials and returns the polynomial that results from multiplying the two polynomials together. A method named evaluatePoly(int x) that takes a value for the variable x and returns the int value of the polynomial when evaluated with the value of x passed into the method. A method named differentiatePoly() that returns the derivative polynomial of the "this" polynomial. In your main method, do the following items in order: 1. Use the readPoly method to allow the user to input the first polynomial. 2. Print the first polynomial for the user. 3. Use the readPoly method to allow the user to input a second polynomial. 4. Print the second polynomial for the user. 5. Present the user with a menu so they can choose to add, multiply, evaluate or differentiate. The menu should repeat until the user chooses to exit. a. If the user chooses to add or multiply, you can assume they are wanting to add or multiply the two previously entered polynomials. b. If the user chooses to evaluate or differentiate a polynomial, you must ask the user which polynomial of the previously two entered polynomials they want to evaluate or differentiate. In the case of evaluation, the user must also provide a value for x. Name your project FirstnameLastnameLab3.java and post it on Blackboard in your lab submission as an attachment. You should only submit the single .java file for grading.

Polynomial Class starter code: import java.util.Scanner; class Polynomial { final int MAXSIZE = 20; int P[]; //holds poly's coefficients int deg; //holds poly's degree Polynomial() { P = new int[MAXSIZE]; deg = -1; } void readPoly() { Scanner input = new Scanner(System.in); System.out.println("Enter a degree: "); deg = input.nextInt(); System.out.println("Next enter the coefficients: "); for (int i = 0; i <= deg; i++){ System.out.println("Enter the coefficient for the term X^"+(deg-i)); P[i] = input.nextInt(); } } void printPoly() { for (int i = 0; i < deg; i++){ if(P[i]!=0) System.out.print(P[i]+"X^"+(deg-i)); if(P[i+1]!=0) System.out.print(" + "); } if(P[deg]!=0) System.out.println(P[deg]); else System.out.println(); } }

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

Students also viewed these Databases questions

Question

4. Describe the factors that influence self-disclosure

Answered: 1 week ago

Question

1. Explain key aspects of interpersonal relationships

Answered: 1 week ago