Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: simple tourney simulator question

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default simple tourney simulator question

    I am trying to make a simple tournament simulator that calls for the user to input team names and ability of the team from 1-100 and then plays a round robin tournament between them where each team plays the other twice. The games are played by generating a random number from 0-sum of the two teams abilities and if it is below the first team that team is the winner.

    import java.util.Scanner;
     
    public class tourney {
    	public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
     
            System.out.print("Please enter the number of teams: ");
            int teamsCount = input.nextInt();
     
    	for (int i = 0; i < teamsCount; ++i) {
                System.out.print("Please enter the name of the team (without spaces): ");
                String name = input.next();
                System.out.print("Please enter the strength of the team (1 - 100): ");
                int strength = input.nextInt();
     
    	}
    }
    }
     
    class Team {
        // The name of the team
        private String name;
        // The strength of the team
        private int strength;
     
        // Constructor, which takes name and strength of the team
        Team(String name, int strength) {
            this.name = name;
            this.strength = strength;
        }
     
        // The method to get the name of the team
        public String getName() {
            return name;
        }
     
        // Get the strength of the team
        public int getStrength() {
            return strength;
        }
     
        // Play a game between the current team (the one, for which this method is called)
        // In other words the first team is this team, the other team is provided as a parameter
        public boolean playGame(Team anotherTeam) {
     
     
        }
    }

    I realize I will have to make a whole other class for tournament but right now I am struggling on just playing the games. I figure I will use a (int)(Math.random * (ability1stteam + ability2ndteam). From the class Team, I understand how to call the first values but will I need to create a whole other class to be able to call the team name and strength from the other team or how would I go about this?

    Thanks for any help that can be provided.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: simple tourney simulator question

    I'm not exactly sure what your question is, but what happened when you tried the approach you described?

    Hint: try creating a function in your tourney class (which really should be Tourney) that creates a Team and prints out the Team's information. Don't worry about the actual tournament until you have that bit done.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Simple Question
    By Natural Noob in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 2nd, 2012, 06:38 PM
  2. Simple Question
    By Natural Noob in forum Java Theory & Questions
    Replies: 1
    Last Post: October 2nd, 2012, 07:26 AM
  3. Simple I/O Question...well could be simple for you?
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 30th, 2011, 06:44 AM
  4. Help with a simple question
    By allea in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 28th, 2011, 07:46 AM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM