Question

ebapps/blackboard/execute/content/file?cmd-view&content jid _975287 1&course id:_693311 Lab 3 Directions (linked lists) Progr
| M (no subject)-nathamat@kear com × ■ Lab 2 (linked lists) (do #1, #2· × ㄨ bapps/blackboard/execute/content/file?cmdaview&co

the language is java
if you coukd shiwnstep by step on how to get each section
L A polynomial can be represented as a linked list, where eoch nede called a polyNede contoins the coefficient and the expone
ebapps/blackboard/execute/content/file?cmd-view&content jid _975287 1&course id:_693311 Lab 3 Directions (linked lists) Program #1 1. Show PolynomialADT interface 2. Create the PolyNodeClass with the following methods: default constructor, . overloaded constructor, copy constructor, setCoefficient, setExponent, setNext, getCoefficient, getExponent, getNext 3. Create the PolynomialDataStrucClass with the following methods: defaut constructor, overloaded constructor, copy constructor, isEmpty. setFirstNode. getfirstNode,addPolyNodeFirst (PolyNode is created and set to the end of polynomial), addPolynomials, toString 4. Create the PolynomialDemoClass: instantiate and initialize objects pl, p2, p3. P4 Add terms to the polynomials (pass 2 arguments to the method: coefficient and exponent- for example: pl.addPolyNodeLast(4, 3):) Print out pl, p2 and sum of the polynomials AND p3, p4, and sum of the polynomials - - Use: pi: 4x 3 3x 2-5 p2 3x 5 4x4x 3-4x2 4x1.2 AND
| M (no subject)-nathamat@kear com × ■ Lab 2 (linked lists) (do #1, #2· × ㄨ bapps/blackboard/execute/content/file?cmdaview&content.ide 975287.1&course jds 69331.1 automatically you can open Lab 2 (linked lists) (do #1, #2 extra credit) due 3/27 here e called a polyNode contoins the coefficient and thr exponent of a term of the polynomial. example, the polynomial 4x3 3x-5 would be represented as the linked list 5 X3 3x2 Write a Polynonial class that has methods for creating a polymomial, reading and writing a polynomial, and adding a pair of polymomials In order to add 2 polynomials, froverse both lists. If a porticular exponent value is present in either one, it should aiso be present in the resulting polymomial uniess its coefficient is zero - 2 Each student at Kean ai y -registrar has decided to use li'or linked lists to store each student's class schedule tokes a differeat number of courses, so the and an array to represent the entire student body A portion of this dete structure is shown below 1 1234 2 35 These data show that the first student (ID: 1111) is taking section 1 of C5C162 for 3 MacBook Pro
L A polynomial can be represented as a linked list, where eoch nede called a polyNede contoins the coefficient and the exponent of a term of the polynomial For example, the polynomial 4x3-5would be represented as the linked list Write a Polynomial class that has methods for creating a pelynomial, reading and writing a polynomial, and adding a pair of pelymomials In order to add 2 polynoriais traverse both lists r, a particular exponent value is present in either one, it should aiso be present in the resulting pelynomial unless its coefficient is zer Esch shidbet n Kean univerty rabes s atterent rumber of courses se the Tokes a different eumber of courses, se the has decided to use inear inked lists to stare each student s class schedule . registrarha and an array to represent the entire student body A portion of s a structure is showm below 1234 364 3 These data show that the first student D) is king section 1 of CSC162 for credits and sectian 2 of HISIO for 4 credts the necend student is net enrelled the s enrolled in Csc23s ectien 4 for 3 creds a class for this data structure Previde netheds for creating the aniginal arey nerting o studen's initial cless schedule, adding a course and drepping o ceurse. Include
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PolyNodeClass.java:

public class PolyNodeClass{

    private int coefficient;
    private int exponent;
    private PolyNodeClass next;

    //default constructor
    public PolyNodeClass(){}

    //overloaded constructor
    public PolyNodeClass(int coefficient, int exponent, PolyNodeClass next) {
        this.coefficient = coefficient;
        this.exponent = exponent;
        this.next = next;
    }

    //copy constructor
    public PolyNodeClass(PolyNodeClass polyNodeClass){
        this.coefficient = polyNodeClass.coefficient;
        this.exponent = polyNodeClass.exponent;
        this.next = polyNodeClass.next;
    }

    public int getCoefficient() {
        return coefficient;
    }

    public void setCoefficient(int coefficient) {
        this.coefficient = coefficient;
    }

    public int getExponent() {
        return exponent;
    }

    public void setExponent(int exponent) {
        this.exponent = exponent;
    }

    public PolyNodeClass getNext() {
        return next;
    }

    public void setNext(PolyNodeClass next) {
        this.next = next;
    }

    @Override
    public String toString() {
        return "PolyNode: " +
                "coefficient=" + coefficient +
                ", exponent=" + exponent +
                ", next=" + next;
    }
}

------------------------------------------------------------------------------------------------------------------------

PolynomialDataStructure.java:

public class PolynomialDataStructureClass{

    private PolyNodeClass firstNode;

    public PolynomialDataStructureClass() { }

    public PolynomialDataStructureClass(PolyNodeClass firstNode) {
        this.firstNode = firstNode;
    }

    public PolynomialDataStructureClass(PolynomialDataStructureClass polynomialDataStructureClass) {
        this.firstNode = polynomialDataStructureClass.firstNode;
    }

    public PolyNodeClass getFirstNode() {
        return firstNode;
    }

    public void setFirstNode(PolyNodeClass firstNode) {
        this.firstNode = firstNode;
    }

    public boolean isEmpty(){
        if(firstNode == null)
            return true;
        return false;
    }

    public void addPolyNodeFirst(int coefficient, int exponent){
        PolyNodeClass node = new PolyNodeClass(coefficient, exponent, null);
        node.setNext(firstNode);
        firstNode = node;
    }

    public void addPolyNodeLast(int coefficient, int exponent){
        PolyNodeClass node = new PolyNodeClass(coefficient, exponent, null);
        if(firstNode == null)
            firstNode = node;
        PolyNodeClass temp = firstNode;
        while(temp.getNext() != null){
            temp = temp.getNext();
        }
        temp.setNext(node);
    }

    public void addPolyNode(int coefficient, int exponent){
        addPolyNodeLast(coefficient, exponent);
    }

    public static void addPolynomials(PolyNodeClass p1, PolyNodeClass p2){
        System.out.println(p1);
        System.out.println(p2);
        p1.setCoefficient(p1.getCoefficient() + p2.getCoefficient());
        p1.setExponent(p1.getExponent() + p2.getExponent());
        System.out.println(p1);
    }

    @Override
    public String toString() {
        return "PolynomialDataStructureClass{" +
                "firstNode=" + firstNode +
                '}';
    }
}
------------------------------------------------------------------------

PolynomialDemoClass.java:

class PolynomialDemoClass{

    public static void main(String[] args) {
        PolynomialDataStructureClass p1 = new PolynomialDataStructureClass();
        p1.addPolyNodeFirst(10, 10);
        PolynomialDataStructureClass p2 = new PolynomialDataStructureClass();
        p2.addPolyNodeFirst(20, 20);

        PolynomialDataStructureClass p3 = new PolynomialDataStructureClass();
        PolynomialDataStructureClass p4 = new PolynomialDataStructureClass();

        PolynomialDataStructureClass.addPolynomials(p1.getFirstNode(), p2.getFirstNode());
    }
}
Add a comment
Know the answer?
Add Answer to:
The language is java if you coukd shiwnstep by step on how to get each section
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java programming course use java import. Follow instructions and comments to explain the code tha...

    java programming course use java import. Follow instructions and comments to explain the code thanks in advance Print L A polymomial can be represented as a linked list, where each node called a polyhede contoins the coefficient and the exponent of a term of the pelynomial For example, The pelynomial 4x-31-5 would be represented as the linked list 3 3xa Write a Polynomial class that has methods for creating a polhynomial, reading and writing a polynomial, and adding a pair...

  • each A polynomial may be represented as a linked list where each node contains the coefficient...

    each A polynomial may be represented as a linked list where each node contains the coefficient and exponent of a term of the polynomial. The polynomial 4X-3X-5 would be represented as the linked list. as the linked list the polnomial eql -5 0 Write a program system that reads two polynomials, stores them as linked lists, adds them together, and prints the result as a polynomial. The result should be a third linked list. Hint: Travers both polynomials. If a...

  • 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...

    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...

  • Create a class to represent a term in an algebraic expression. As defined here, a term...

    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...

  • Polynomial Using LinkedList class of Java Language Description: Implement a polynomial class using a LinkedList defined...

    Polynomial Using LinkedList class of Java Language Description: Implement a polynomial class using a LinkedList defined in Java (1) Define a polynomial that has the following methods for Polynomial a. public Polynomial() POSTCONDITION: Creates a polynomial represents 0 b. public Polynomial(double a0) POSTCONDITION: Creates a polynomial has a single x^0 term with coefficient a0 c. public Polynomial(Polynomial p) POSTCONDITION: Creates a polynomial is the copy of p d. public void add_to_coef(double amount, int exponent) POSTCONDITION: Adds the given amount to...

  • For this lab, you must define a class called Polynomial. This class definition must include the f...

    Please answer this in python 3, thank you. For this lab, you must define a class called Polynomial. This class definition must include the following methods: ._init_0- the initialiser for the class ._str_0- returns a formatted string representation of a Polynomial object add_term) - adds a new term (coefficient and exponent) to the Polynomial .addo-modifies the existing Polynomial by adding another one to it ._add_0-returns a new Polynomial object that is the sum of two polynomials scale) - scales a...

  • Using C++ language, write a code to implement the "evaluate function" described below using the given...

    Using C++ language, write a code to implement the "evaluate function" described below using the given poly.cpp file and poly.h header file. (ignore the other 3 functions if asked) poly.cpp file: poly.h header file: You are asked to implement four functions for a data structure used to store polynomials. The data structure used for polynomials is a linked list that consists of terms where each term consists of a coefficient, an exponent and a pointer to the next term. A...

  • In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and...

    In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and linked lists. You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: 1. description - which is a string 2. write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money...

  • For this lab, you must define a class called Polynomial. This class definition must include the f...

    please answer this question in python 3 For this lab, you must define a class called Polynomial. This class definition must include the following methods: ._init_0- the initialiser for the class ._str_0- returns a formatted string representation of a Polynomial object add_term) - adds a new term (coefficient and exponent) to the Polynomial .addo-modifies the existing Polynomial by adding another one to it ._add_0-returns a new Polynomial object that is the sum of two polynomials scale) - scales a Polynomial...

  • C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve...

    C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve very big integer calculations that are outside the limit of all available primitive data types. For example, factorial of 100 contains 158 digits in it so we can’t store it in any primitive data type available. We can store as large Integer as we want in it. Your goal is to overload the operators for a generic “BigInt” class. You will need to write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT