I'm back again with some more Java. I am getting better at it and I've learned quite a bit, but I'm having some trouble with some mini programs. My assignment is to do seven Project Euler problems and I've completed one and have five that are close to working. Any more help would be greatly appreciated
Here is what I need to do, "Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed four million."
I have this so far and it outputs a number, but its not right.
Last edited by sox 06 on Wed Jan 27, 2010 9:22 pm, edited 2 times in total.
I know Java, but I'll admit to being rusty, having not programmed in it for a while.
I don't reckon to be much help with the math bit, but start out with the variables. You know that you have placeholders such as the current hole #, total strokes, score, et. al. Each time there's an event, you can update the placeholder by the current value(s) within the second while loop.
Each time the user hits the ball, I'm presuming that you figure out the metrics (strength, angle) by a formula or two (I'm assuming something Pythagorean theorem based), with some help from the geometry AWT package Once that's figured out, you're calling the AWT/Swing methods to draw the path of the ball. If ballInHole is true, then you're scoring the hole into the # holes played, total number of strokes, handicap and emptying out # strokes, as well assuming that for the next hole someone hits a hole in one (in other words, you have a negative number starting from the hole, such that for each additional stroke, you're incrementing up). Assuming there's an array of holes which tell you the par and the number of feet away from tee shot, then it should be straightforward to keep score. If false, well, then you carry on. You're adding one more stroke to the stroke count for the hole and taking into account the number of feet away from the cup.
Not sure if I've got the whole picture here, but basically that would be one way to approach the problem. Good luck.
Alright, I got the game to play like it should and all I have left is a few print line things. I need to output the number of strokes for each hole as well as the number of strokes for the round. I have both of those working, except I can't seem to get the number of strokes per hole (numHoleStrokes) to reset to zero after each hole. Any ideas?
Assigning the variable to 0 after all the hole accounting is done isn't working? Or even better, put the assignment in the beginning of the loop that is cycling through 18 holes, so it is reset to 0 at the start of each hole instead of at the end.
Tavish wrote:Assigning the variable to 0 after all the hole accounting is done isn't working? Or even better, put the assignment in the beginning of the loop that is cycling through 18 holes, so it is reset to 0 at the start of each hole instead of at the end.
I forgot to set it to zero
This is my first time writing any kind of program so I'm not very good at it. I set numHoleStrokes = 0; right below System.out.println("Number of Total Strokes:" + numTotalStrokes); and it works now.
One last thing and I'll be done
Its suppose to ask the player if they want to play the next hole. So after the first hole is done, a prompt such as "Do you want to continue playing?" should come up and a "true" or "false" answer will either continue to the next hole or exit the program. I'm not really sure how to do this.
I saw the thread title and got all excited thinking I'd finally be able to put my degree in South Pacific Studies to use, but alas, you're talking about the computer program. I don't know anything about computers, but if anyone has any questions about the most heavily populated island in the world, let me know.
Art Vandelay wrote:I saw the thread title and got all excited thinking I'd finally be able to put my degree in South Pacific Studies to use, but alas, you're talking about the computer program. I don't know anything about computers, but if anyone has any questions about the most heavily populated island in the world, let me know.
Question: Is that why you're such a grumpy person?