Any Java Experts? More Help! - Fantasy Baseball Cafe 2013

## Any Java Experts? More Help!

Moderator: Baseball Moderators

### Any Java Experts? More Help!

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.
sox 06
General Manager

Posts: 4424
(Past Year: 22)
Joined: 22 Apr 2006
Bases this season: 12
Home Cafe: Baseball

### Re: Any Java Experts?

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.
The Artful Dodger
Chief Wikitect

Posts: 21244
(Past Year: 115)
Joined: 3 Feb 2006
Bases this season: 47
Home Cafe: Baseball
Location: Not nineteen forever

### Re: Any Java Experts?

Dude, just copy the code from Wii Sports, you'll be fine

Rocinante2: you know
Rocinante2: its easy to dismiss the orioles as a bad team
ofanrex: go on
Rocinante2: i'm done
Rocinante2: lmao

Play Brushback Baseball! (we need more people)
Neato Torpedo
Hall of Fame Hero

Posts: 8618
(Past Year: 3)
Joined: 4 Mar 2007
Bases this season: 77
Home Cafe: Baseball
Location: we don't burn gasoline, we burn our dreams

### Re: Any Java Experts?

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?

sox 06
General Manager

Posts: 4424
(Past Year: 22)
Joined: 22 Apr 2006
Bases this season: 12
Home Cafe: Baseball

### Re: Any Java Experts?

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.

Bury me a Royal.
Tavish
Mod in Retirement

Posts: 11029
(Past Year: 109)
Joined: 3 May 2004
Bases this season: 1,135
Home Cafe: Baseball

### Re: Any Java Experts?

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.
sox 06
General Manager

Posts: 4424
(Past Year: 22)
Joined: 22 Apr 2006
Bases this season: 12
Home Cafe: Baseball

### Re: Any Java Experts?

Write your question to the user;
Compare answer and either continue or quit.

Bury me a Royal.
Tavish
Mod in Retirement

Posts: 11029
(Past Year: 109)
Joined: 3 May 2004
Bases this season: 1,135
Home Cafe: Baseball

### Re: Any Java Experts?

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
Hall of Fame Hero

Posts: 5264
(Past Year: 30)
Joined: 12 Mar 2005
Bases this season: 41
Home Cafe: Baseball

### Re: Any Java Experts?

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?
JTWood
Hall of Fame Hero

Posts: 11508
Joined: 22 Jun 2004
Bases this season: 0
Home Cafe: Baseball
Location: Unincorporated Heaven

### Re: Any Java Experts?

Is what why?

Also, I'm not grumpy at all.
Art Vandelay
Hall of Fame Hero

Posts: 5264
(Past Year: 30)
Joined: 12 Mar 2005
Bases this season: 41
Home Cafe: Baseball

Next

### Who is online

Users browsing this forum: Aaabroarlyrort, Ajqpvzdw, Biptprepala, ciptplearee, HerEffermax, NaibraAxiolla, oragmaavafe, RoniLypeintit, ruidgidly, Warlwheelry, zasonge62 and 7 guests

Forums Articles & Tips Sleepers Rankings Leagues

Today's Games
Wednesday, May. 22
(All times are EST, weather icons show forecast for game time)

 • Minnesota at Atlanta(12:10 pm)
 • LA Dodgers at Milwaukee(1:10 pm)
 • Cincinnati at NY Mets(1:10 pm)
 • Oakland at Texas(2:05 pm)