Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
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
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

# help with this problem

Greenhorn
Posts: 14
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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: 24204
44
• Number of slices to send:
Optional 'thank-you' note:
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: 17346
11
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
well im not asking for the exact solution, im only asking for some hint or suggestion on how to start the program...

Sheriff
Posts: 16917
283
• Number of slices to send:
Optional 'thank-you' note:
Well, if it's a hint you're looking for:

Mark Spritzler
ranger
Posts: 17346
11
• Number of slices to send:
Optional 'thank-you' note:
Jayson, thanks very much for changing your display name, looks really good now.

Mark

Mark Spritzler
ranger
Posts: 17346
11
• Number of slices to send:
Optional 'thank-you' note:
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

 Skool. Stay in. Smartness. Tiny ad: free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter