Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's the problem here?

 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This program should take input as follows:

enter number of players,i.e. "2"

enter number of games, i.e. "1"

game 1, player number: "1"
hits: 1
walks: 2
outs: 3

game 1, player number: "2"
hits: 3
walks: 2
outs: 1

game 1, player number: [enter "-1" when all players are accounted for]

2 3 2 1
2 3 2 1

the output should be:

1 1 2 3
2 3 2 1

What is wrong with the the program?



 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • If it doesn't compile, then what are the errors?
  • If it generates runtime errors, then what are these errors?
  • If it compiles and runs, but gives unexpected output, then what is the output?

  • [ April 22, 2006: Message edited by: marc weber ]
     
    Jesse Crockett
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Pardon, but all three of those bullet points are accounted for.
    If there were compilation or runtime errors, I would have noted them.
    Surely you won't miss the given output...
    [ April 22, 2006: Message edited by: Jesse Crockett ]
     
    Michael Dunn
    Ranch Hand
    Posts: 4632
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    > Surely you won't miss the given output...

    Surely you don't expect everyone to have your Player class so we can
    run the program and observe the given output
     
    Jesse Crockett
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You mean the Player class in my post?

    How does either response make sense?
     
    Keith Lynn
    Ranch Hand
    Posts: 2409
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I believe the problem you're experiencing is because the variables inside the Player class are static. This means that no matter how many instances of Player you create, there will only be one copy of those variables.
     
    Jesse Crockett
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks, that solves it.
     
    marc weber
    Sheriff
    Posts: 11343
    Java Mac Safari
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Jesse Crockett:
    ...Surely you won't miss the given output...

    Actually, I did miss that. I didn't realize that the first example was output. Sorry.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic