This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes help with this problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with this problem" Watch "help with this problem" New topic
Author

help with this problem

jayson clark
Greenhorn

Joined: Mar 14, 2005
Posts: 14
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...
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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:


There is no emoticon for what I am feeling!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
jayson clark
Greenhorn

Joined: Mar 14, 2005
Posts: 14
well im not asking for the exact solution, im only asking for some hint or suggestion on how to start the program...
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4442
    
    5

Well, if it's a hint you're looking for:



Junilu - [How to Ask Questions] [How to Answer Questions]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Jayson, thanks very much for changing your display name, looks really good now.

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with this problem
 
Similar Threads
stars
please help me
Math.pow
Same old problems
Method Overloading?