• 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

help with this problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need write a method, called calculateFunction, that calculates the value of y for various values of x. The declaration of this method is below:

public int calculateFunction(int x);
The calculateFunction method calculates the function y = x + x2 + 2x. To calculate the values of this expression, you can use:

x2 = x * x
2x = Math.pow(2,x)

Note that because calculateFunction works in terms of int, and Math.pow returns a double, you must cast the value returned to an int, or Java will give you a compiler error about loss of precision.

Once the function has been calculated, print out the relative size of the result by calling the method printStars used in module 3 of the course modules. Calculate this function and print out its relative size for values from 1 to 10. Note that to make the number of stars reasonable, you should print out 1 star for each value of 10 returned (for example, if 62 is returned, you should print out 6 stars). You can do so by dividing by 10, noting that the value will be truncated to the next lowest int value.

Im very new and can anybody help be how to begin this problem..just the basic idea? plzzz...
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps if you posted your instructor's email account we could directly
email the solution to them, and that would save you even more time. :roll:
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You also need to comply with the JavaRanch JavaRanch policy on display names before most folks will feel inclined to help you. You can change your name to a suitable firstname lastname combination by visiting here.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JC, this is your second notice at least. If you don't comply with the naming policy in 24 hours, your account will be suspended.

Mark
 
jayson clark
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well im not asking for the exact solution, im only asking for some hint or suggestion on how to start the program...
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if it's a hint you're looking for:

 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayson, thanks very much for changing your display name, looks really good now.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so you have this

public int calculateFunction(int x) {
}

Inside it will calculate your function.

Do you understand this statement?

Note that because calculateFunction works in terms of int, and Math.pow returns a double, you must cast the value returned to an int, or Java will give you a compiler error about loss of precision.



Not sure if that is you posting or from your instructor's instructions.

After you get the result, you need to divide by 10, which of course there you should see a float/double, but I think to get the lower int value there is a method in Math that you can find.

If you haven't looked at the Java API Javadocs, I suggest you look there for what methods are available and what they do.

Here's a link to the main JavaDoc page, on the left you can scroll through the classes and find the Math class, click that link and on the right is the information you will need.

Good Luck

Mark
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic