• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what does this mean?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
convert code into a method with header:

I just wrote a code to multiply two polynomials together but I dont know what it means to convert it into a method with a header, thanks..

public class MultPoly // tests multiplication of two polynomials

{
public static void main (String[] args)
{

int[] p = {2, 5, 3, 4};
int m = p.length - 1; // degree of p
int[] q = {4, 6, 8};
int n = q.length - 1; // degree of q
int[] r = new int [m + n + 1];// This will store the product.

for (int i = 0; i < p.length; i++)
{ //increments leading coefficient
for (int x=0; x < q.length; x++)
{
r[i + x] += (p[i] * q[x]);
}
}//for

int k;

for (k = 0; k < r.length - 1; k++)
{
System.out.print (r[k] + ", ");
}
System.out.println (r[k] + "."); // prints out final digit of polynomial

}//main

}//class
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would assume this means to extract the functionality that relates explicitly to the multiplication of polynomials and place that into a function and pass the values as needed to this function.
What you have at the moment is a lump of code that will only calculate for one set of particular values and makes it difficult to reuse the benefits of code already written without rewriting substantial amounts of it.

To get you started the declaration of this would look something like


With reagrds to the header I don't know what that is .. Java doesn't use header filesperhaps you can get some clarification from whoever assigned you this project!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic