This discussion is archived
4 Replies Latest reply: Dec 18, 2012 7:25 AM by 980538 RSS

Java Tournament Code

980538 Newbie
Currently Being Moderated
Hey, I currently have to write a program that will simulate a tournament that takes place between a number of entrants. The details of this program are as follows -

Learning Outcomes
This addresses the following learning outcomes


• Be able to implement, compile, test and run Java programmes, comprising more than
one class, to address a particular software problem.
• Demonstrate the ability to employ various types of selection constructs in a Java pro- gram.
• Demonstrate the ability to employ repetition constructs in a Java program.
• Demonstrate the ability to use simple data structures like arrays in a Java program.
Requirements. Design, implement and test a tournament as described below. A tourna- ment is a (ordered) list of players. A player has a name and the number of matches won and lost (non-negative integers). Shown below is a tournament before any matches have been played so the number of matches won and lost is zero in each case. The number at the begin- ning of each line is their current position in the tournament. Initially this will be the order the players are input. The number of games played is calculated from sum of the number of games won and the number lost.
0: Susie: Played 0, Won 0, Lost 0 1: Abdul: Played 0, Won 0, Lost 0 2: Jean: Played 0, Won 0, Lost 0 3: Pete: Played 0, Won 0, Lost 0 4: Sara: Played 0, Won 0, Lost 0
A player (a challenger) is allowed to challenge another player (the opponent) who is above them in the list. To challenge a player the position of the challenger and the opponent are input. If the challenger wins, the challenger and the opponent swap positions. For example if Pete challenges Abdul (this is allowed as Abdul is above Pete in the tournament) and wins, Pete moves to position 1 and Abdul moves to position 3. The number of matches played, won and lost are incremented to reflect this. Pete has now played and won one match and Abdul has played and lost one match.
0: Susie: Played 0 Won 0 Lost 0
1: Pete: Played 1 Won 1 Lost 0
2: Jean: Played 0 Won 0 Lost 0
3: Abdul: Played 1 Won 0 Lost 1
4: Sara: Played 0 Won 0 Lost 0
1

Lab10

2 If Jean challenges Susie but Jean loses the order remains unchanged. Jean has now played
and lost one match and Susie has played and won one match.
0: Susie: Played 1 Won 1 Lost 0 1: Pete: Played 1 Won 1 Lost 0 2: Jean: Played 1 Won 0 Lost 1 3: Abdul: Played 1 Won 0 Lost 1 4: Sara: Played 0 Won 0 Lost 0
If Pete challenges Jean this is not allowed as Jean is below Pete in the tournament. Similarly a player isn’t allowed to challenge themselves. Initially the names of players should be entered by the user. To represent challenges, the position of the challenger and the opponent are input by the user (using a loop). Assume that the input of a negative challenger position means no more challenges are to be input. Otherwise, if a position is entered that doesn’t exist the user should be informed and allowed to re-enter this.

I have a few ideas of how best to proceed with this code but i'm not 100% sure. Does any one have any tips or hints that may be able to help? If so please get back to me.

Thanks, Mike
  • 1. Re: Java Tournament Code
    Kayaman Guru
    Currently Being Moderated
    977535 wrote:
    I have a few ideas of how best to proceed with this code but i'm not 100% sure. Does any one have any tips or hints that may be able to help? If so please get back to me.
    Share your ideas and tell us where you're having trouble and we'll give you tips and hints.
  • 2. Re: Java Tournament Code
    980538 Newbie
    Currently Being Moderated
    thanks for the quick reply. I can get all the tournament info i.e players input but once i actually want to get the tournament started how do i allow certain matches to take place/ not take place depending on whether they can, and once the match has been simulated and we have a result how to get this to auto update my table?? I thought of using if else statements but this could get messy if trying to sim multiple games or if they are not allowed (i.e the player cannot challenge another player due to the rules of the tournament.) would i be better off using some kind of loop that will allow the match to take place and then break from that when my table changes and the conditions are no longer met?
    thanks, Mike
  • 3. Re: Java Tournament Code
    Kayaman Guru
    Currently Being Moderated
    You should probably write out on paper some of the methods and classes you need. Forget about how for now, concentrate on what. When you come up with the methods/operations, as well as the classes you need (like, can a particular match take place and a class for a competitor), then you can think about the actual implementation.

    It's a lot easier to plan ahead instead of trying to go straight into the code (especially if you're not experienced with programming).
  • 4. Re: Java Tournament Code
    980538 Newbie
    Currently Being Moderated
    ok, thanks for your help. need to do a bit more planning on this and i will get back to you once i have a better idea of which route to go down and how to put together all the necessary methods needed to run the tournament.
    thanks, mike

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points