Any Java Experts? More Help! - Fantasy Baseball Cafe 2014 Fantasy Baseball Cafe
100% Deposit Bonus for Cafe Members!

Return to General Talk

Any Java Experts? More Help!

Moderator: Baseball Moderators

Any Java Experts? More Help!

Postby sox 06 » Thu Nov 05, 2009 6:07 pm

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 ;-D

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."


Image

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
General Manager

User avatar
CafeholicEagle Eye
Posts: 4425
Joined: 22 Apr 2006
Home Cafe: Baseball

Re: Any Java Experts?

Postby The Artful Dodger » Thu Nov 05, 2009 7:36 pm

I know Java, but I'll admit to being rusty, having not programmed in it for a while. :-B

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. ;-D
Image

It's kinda like the Old Cafe - http://fbc2.freeforums.net
The Artful Dodger
Chief Wikitect
Chief Wikitect

User avatar
CafeholicResponse TeamFantasy ExpertCafe WriterCafe RankerMock(ing) DrafterEagle EyePick 3 Weekly WinnerMatchup Meltdown SurvivorLucky Ladders Weekly Winner
Posts: 21947
(Past Year: 670)
Joined: 3 Feb 2006
Home Cafe: Baseball
Location: Downloading rice

Re: Any Java Experts?

Postby Neato Torpedo » Fri Nov 06, 2009 1:37 am

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

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

User avatar
EditorCafeholicFantasy ExpertCafe WriterCafe RankerWeb Supporter
Posts: 8618
Joined: 4 Mar 2007
Home Cafe: Baseball
Location: we don't burn gasoline, we burn our dreams

Re: Any Java Experts?

Postby sox 06 » Tue Nov 17, 2009 1:29 pm

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?

Image
sox 06
General Manager
General Manager

User avatar
CafeholicEagle Eye
Posts: 4425
Joined: 22 Apr 2006
Home Cafe: Baseball

Re: Any Java Experts?

Postby Tavish » Tue Nov 17, 2009 1:35 pm

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.
Image

Bury me a Royal.
Tavish
Mod in Retirement
Mod in Retirement

User avatar
CafeholicFantasy ExpertCafe WriterCafe RankerMock(ing) DrafterEagle EyeCafe SpotterWeb Supporter
Posts: 11070
(Past Year: 25)
Joined: 3 May 2004
Home Cafe: Baseball

Re: Any Java Experts?

Postby sox 06 » Tue Nov 17, 2009 1:52 pm

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
General Manager

User avatar
CafeholicEagle Eye
Posts: 4425
Joined: 22 Apr 2006
Home Cafe: Baseball

Re: Any Java Experts?

Postby Tavish » Tue Nov 17, 2009 2:15 pm

Write your question to the user;
String answer = input.nextLine();
Compare answer and either continue or quit.
Image

Bury me a Royal.
Tavish
Mod in Retirement
Mod in Retirement

User avatar
CafeholicFantasy ExpertCafe WriterCafe RankerMock(ing) DrafterEagle EyeCafe SpotterWeb Supporter
Posts: 11070
(Past Year: 25)
Joined: 3 May 2004
Home Cafe: Baseball

Re: Any Java Experts?

Postby Art Vandelay » Tue Nov 17, 2009 2:41 pm

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.
Image
Art Vandelay
Hall of Fame Hero
Hall of Fame Hero

CafeholicFantasy ExpertPick 3 Weekly WinnerLucky Ladders Weekly Winner
Posts: 5265
Joined: 12 Mar 2005
Home Cafe: Baseball

Re: Any Java Experts?

Postby JTWood » Tue Nov 17, 2009 7:59 pm

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

User avatar
CafeholicCafe WriterEagle EyeWeb Supporter
Posts: 11508
Joined: 22 Jun 2004
Home Cafe: Baseball
Location: Unincorporated Heaven

Re: Any Java Experts?

Postby Art Vandelay » Tue Nov 17, 2009 9:18 pm

Is what why?

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

CafeholicFantasy ExpertPick 3 Weekly WinnerLucky Ladders Weekly Winner
Posts: 5265
Joined: 12 Mar 2005
Home Cafe: Baseball

Next

Return to General Talk

Who is online

Users browsing this forum: unioreimi and 8 guests

Forums Articles & Tips Sleepers Rankings Leagues


Today's Games
Friday, Oct. 24
(All times are EST, weather icons show forecast for game time)

Kansas City at San Francisco
(8:07 pm)

  • Fantasy Baseball
  • Article Submissions
  • Privacy Statement
  • Site Survey 
  • Contact