Generate and display the polynomial

Assignment Help JAVA Programming
Reference no: EM131064978

Consider the polynomials with integer coefficients and positive integer exponents:

P(x) = a0 * x0 + a1 * x1 + ... + an-1 * xn-1

For programming purposes, a polynomial is represented as an array of integers. The array cell of index i corresponds to the polynomial coefficient ai, where i represents the exponent of the variable x.

For example, if the polynomial is P(x) = 2 * x3 - 9 * x2 + 0 * x1 + 8 * x0, its representation as an array of size 4 is shown below:

8 0 -9 2
0 2 2 3

Consider the problem of calculating the polynomial value for an integer value of its variable x.

As an example, for the above polynomial and for x = 2, the value of P(2) is -12.

a) Design and write the methods calculateBruteForce and calculateHorner for calculating the polynomial value for an integer value of x by using the brute force approach and respectively Horner's technique. Each method should take two parameters: the array of coefficients representing the polynomial and the value of x.

When implementing calculateBruteForce method, define and invoke your own method for raising x to a given power by using repetitive multiplications, instead of invoking a predefined method such as the Math.pow().

(a1) By analyzing the code, determine and indicate time complexity for each of the two methods in terms of Big-O notation.

(a2) Which of the two methods would perform better in terms of execution time? Explain.

b) Write a driver program PolyVal.java to validate the conclusions drawn from question a2). Consider a polynomial with 10 terms whose coefficients are stored in an integer array and are randomly generated in the interval -9 .. 9. Implement the following actions:

(b1) Generate and display the polynomial.

(b2) Generate and display a random integer value x in the interval 1 .. 9.

(b3) Invoke the two methods and display the polynomial value returned by each method for the x value generated at (b2).

(b4) Measure and display the execution time of the two methods as the arithmetic mean value of 1010 executions. Use the method System.nanoTime() for determining the execution time. Discuss the obtained results. Are the results in line with your answer to question a?

Note. Due to the behavior of the JVM and JIT compiler, the execution time of the repeated programs is much slower the first times they are run and therefore make sure to discard the measured values for the initial 10 runs.

Submission requirements

Submit the following before the due date listed in the Calendar:

1. The source file PolyVal.java.

The source code should use Java code conventions and professional code layout regarding white space management, indents and comments.

2. The Solution description document <YourSecondName>_HW1 (.pdf or .doc / .docx) containing:

(2.1) assumptions, main design decisions, error handling; (2.2) test cases and two relevant screenshots; (2.3) the answer and discussion required by questions a2) and b4); (2.4) lessons learned and (2.5) possible improvements. The size of the document file (including the screenshots) should be of two pages, single spaced, font size 10.

Reference no: EM131064978

Questions Cloud

Determine the length of the channel : Determine the depth of the channel below the existing ground level if the minimum cross section area of the channel is 8 m2 and hence determine the channel profile equation.
What is the absolute error : Voltmeter is accurate 98% of its full scale reading. If the voltmeter reads 200V on 500V range, what is the absolute error? What is the percentage error of the reading in (i)
Determine the minimum power supplied to the heat : If the house loses heat to the atmosphere at the rate of 64,000 kJ/h, determine the minimum power supplied to the heat pump, in kW.
Capital asset pricing model and arbitrage pricing theory : Describe the underlying assumptions and differences for the Capital Asset Pricing Model (CAPM) and the Arbitrage Pricing Theory (APT). Provide an example in which type of situation each would be most appropriate to the task. Is there any situation in..
Generate and display the polynomial : Design and write the methods calculate Brute Force and calculate Horner for calculating the polynomial value for an integer value of x by using the brute force approach and respectively Horner's technique. Each method should take two parameters: t..
Evaluate the temperature at inner and outer surfaces of wall : Obtain a relation for the variation of temperature in the wall by solving the differential equation. Evaluate the temperatures at the inner and outer surfaces of the wall
The market yield for bonds of similar risk and maturity : A company issued 10%, 10-year bonds with a face amount of $100 million. The market yield for bonds of similar risk and maturity is 8%. Interest is paid semiannually. At what price did the bonds sell? (FV of $1, PV of $1, FVA of $1, PVA of $1, FVAD of..
Determine the coordinates and of the centroid c of area : Determine the coordinates and of the centroid C of the area shown in the figure.
Prepare the adjusting journal entries necessary : Sally's rice is unable to reconcile the bank balance at January 31. Sally's reconciliation is shown here. What is the proper adjusted cash balance per bank? What is the proper adjusted cash balance per books?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write the string copy and string concatenation functions

Write the string copy and string concatenation functions and first version should use array subscripting, and the second version should use pointer arithmetic.

  Following names with an associated phrase

Name game (8 points). Match the following names with an associated phrase. Use each letter once and only once. A. Steve Cook _______ Incompleteness B. Alan Turing _______ Reductions

  Methods

Assignment describe the basic working of methods. How to write a method in java and how to call a method.

  Establish a connection to the mycustomers database

Write a Java program to establish a connection to the MyCustomers database using the JDBC driver to retrieve the entire Customers and Orders table.

  Powerful pain reliever are consumers with headaches

Your target market for the most powerful pain reliever are consumers with HEADACHES. Start with goals and objectives. Do a SWOT. What information is most important for your market? Do some market research.

  Concept of operator overloading

This lab is to introduce students to the concept of operator overloading as member functions of a class. This will be done in the context of creating a class that will perform four basic mathematical operations on complex numbers

  Create and code a program uses three parallel numeric array

Create and code a program that uses three parallel numeric arrays of size 6. The program searches one of the arrays and then displays the corresponding values from the other two arrays. The program should prompt the user to enter a ProductID. Valid P..

  Find the solution of all these java question

find the solution of all these java question

  Produces a simple formatted report

For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below)

  Create an application for kochs cottages

Create an application for Koch's Cottages, a weekend getaway resort that rents boats and cottages to use on the local lake.

  Values that occur just once

This list has some values that occur just once (1, 3, 4, 11, 13, 18), some values that occur twice (9, 16), some values that occur three times (14, 19) and a single value that occurs four times (7). Therefore, the call of list.maxCount() should re..

  Concepts of polymorphism

This lab introduces students to the concepts of polymorphism, early binding, late binding, abstract classes, and virtual class functions. This will be done in the context of performing calculations on basic geometrical shapes

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd