Its a report . Implement and test a preliminary version of the polynomial class, using a small array to store the coefficients of the polynomial in order of increasing exponents, following the design pattern of object-oriented approach. Suppose the range of the exponents is in [0, 30). • Use an array as a private member variable. • insert(), adding a new term on specific exponent. • remove(), deleting a term. • Have a add() method, deciding the parameters and the return value by yourself. • Have a sub() method, deciding the parameters and the return value by yourself. • A printout() method to display the polynomial expression. • And other variables, or methods if needed. • Do the algorithm analysis on the implemented method, and give the big O notation estimation. You will also need to write a Polynomial Test program to initialize two linear polynomial objects and apply the operation on it and also display the result. For example, P1=x + 3x5 - 5x8; P2= 2x3 - 4x5+ 2x7; So P3= P1+P2= x +2x3 - x5+ 2x7 - 5x8, P4 = P1-P2 = x - 2x3 + 7x5- 2x7 - 5x8. In this project, only one variable is considered, we don’t have the polynomial such as x+3x5 3y3 .
Problem Statement Specifying the problem requirements forces you to state the problem clearly and unambiguously to gain a precise understanding of what is required for its solution. Your objective is to eliminate unimportant aspects and zero in on the root problem.
Analysis Analyzing the problem involves identifying the problem inputs (the data you have to work with), outputs (the desired results), and any additional requirements for or constraints on the solution. At this stage, you should also determine the format in which the results should be displayed and develop a list of problem variables and their relationships. These relationships may be expressed as formulas. Design & Class Prototype Designing the algorithm to solve the problem requires you to develop a list of steps (an algorithm) to solve the problem and then verify that the algorithm solves the problem as intended.
Design information, in particular, can frequently be conveyed much more effectively with drawings or charts than with words alone. Class prototype is the contract of a class, as an outline class declaration showing only public fields and the heading of the constructor and methods. Display the class prototype and also show the relationship between different classes.
Testing and verifying the program requires some testing cases to verify the completed program working as desired. Don’t rely on just one test case; run the program several times using different sets of data, making sure that it works correctly for every situation provided for in the algorithm.
Conclusion If it is an unsuccessful one, then what is the reason why you failed?
Answer:-
The below is the required source code for the given problem in JAVA
Code:-
import java.util.Scanner;
public class PolyNomialTest {
public static void main(String[] args) throws
Exception{
Scanner sc = new
Scanner(System.in);
System.out.println("Enter
polynomial 1");
Polynomial pn1 =
PolyNomialTest.readPn(sc);
System.out.println("Enter
polynomial 2");
Polynomial pn2 =
PolyNomialTest.readPn(sc);
pn1.print();
pn2.print();
Polynomial pn3 =
pn1.add(pn2);
System.out.println(" Addition
");
pn3.print();
Polynomial pn4 =
pn1.subtract(pn2);
System.out.println(" Subtraction
");
pn4.print();
}
public static Polynomial readPn(Scanner sc) {
Polynomial pn = new
Polynomial();
int[] expCoeff = new
int[Polynomial.MAX_EXPONENT];
System.out.println("Enter -1 for
exponent power to quit \n Enter polynomial terms: ");
while(true) {
System.out.println("Enter exponent power : ");
int exp =
sc.nextInt();
if(exp <
0)
break;
System.out.println("Enter Coefficient of exponent : ");
int coeff =
sc.nextInt();
pn.insert(exp,
coeff);
}
return pn;
}
}
class Polynomial {
private int[] expCoeff; //in increasing order o = x^0,
1 = x^1 etc
public static int MAX_EXPONENT = 30;
public Polynomial() {
expCoeff = new
int[MAX_EXPONENT];
for(int i = 0; i <MAX_EXPONENT;
i++ )
expCoeff[i] =
0;
}
public void insert(int term, int coeff) {
if(term < MAX_EXPONENT)
expCoeff[term] = coeff;
}
public void remove(int term) {
expCoeff[term] = 0;
}
public Polynomial add(Polynomial p2) {
Polynomial p3 = new
Polynomial();
int[] coeff = new
int[MAX_EXPONENT];
for(int i = 0; i <MAX_EXPONENT;
i++ ) {
coeff[i]=
this.getExpCoeff(i)+ p2.getExpCoeff(i);
}
p3.setExpCoeff(coeff);
return p3;
}
public Polynomial subtract(Polynomial p2) {
Polynomial p3 = new
Polynomial();
int[] coeff = new
int[MAX_EXPONENT];
for(int i = 0; i <MAX_EXPONENT;
i++ ) {
coeff[i]=
this.getExpCoeff(i) - p2.getExpCoeff(i);
}
p3.setExpCoeff(coeff);
return p3;
}
public void print() {
String pn = "";
for(int i = MAX_EXPONENT-1; i
>=0; i-- ) {
pn +=
pn.equals("") ? "" : "+";
if(expCoeff[i]
!= 0) {
pn += expCoeff[i];
if(i != 0)
pn += " * x^"+i;
}
}
System.out.println(pn);
}
public int getExpCoeff(int term) {
return expCoeff[term];
}
public int[] getExpCoeff() {
return expCoeff;
}
public void setExpCoeff(int[] expCoeff) {
this.expCoeff = expCoeff;
}
}
If you find any
difficulty with the code, please let know know I will try for any
modification in the code. Hope this answer will helps you. If you
have even any small doubt, please let me know by comments. I am
there to help you. Please give Thumbs Up,Thank You!! All the
best
Its a report . Implement and test a preliminary version of the polynomial class, using a...
Create a class to represent a term in an algebraic expression. As defined here, a term consists of an integer coefficient and a nonnegative integer exponent. E.g. in the term 4x2, the coefficient is 4 and the exponent 2 in -6x8, the coefficient is -6 and the exponent 8 Your class will have a constructor that creates a Term object with a coefficient and exponent passed as parameters, and accessor methods that return the coefficient and the exponent. Your class...
A polynomial p(x) is an expression in variable x which is in the form axn + bxn-1 + …. + jx + k, where a, b, …, j, k are real numbers, and n is a non-negative integer. n is called the degree of polynomial. Every term in a polynomial consists of a coefficient and an exponent. For example, for the first term axn, a is the coefficient and n is the exponent. This assignment is about representing and computing...
Description Create a polynomial class with linked lists and implement some basic functions. Specifications Polynomials are stored in a linked list of Term objects (two classes: Polynomial and Term). Term objects have two data fields: coefficient and exponent, both positive integers. Polynomial will have some methods that create linked list functionality, but not all list operations are needed; include only those used by this program. Do not use a separate linked list class. The list will be non-circular. Make a...
(The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...
Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...
import java.util.*; /** Description: This program determines the average of a list of (nonnegative) exam scores. Repeats for more exams until the user says to stop. Input: Numbers, sum, answer Output: Displays program description Displays instruction for user Displays average Algorithm: 1. START 2. Declare variables sum, numberOf Students, nextNumber, answer 3. Display welcome message and program description 4. DOWHILE user wants to continue 5. Display instructions on how to use the program 6. Inititalize sum and number of student...
Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...
Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...
Objective: To implement the programming languages features discussed in class and to develop a program that uses Graphical User Interfaces (GUI) that provides a friendly environment for users. Project Assignment Design and implement a Hotel Reservation System. The hotel has two types of rooms. One is regular room that has two beds. Another is deluxe room that has two beds and a safe. The regular room price is $120 per night. The deluxe room is $130 per night. A safe...
in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...