Results 1 to 4 of 4
  1. #1
    xEthan is offline Member
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Question How to get multiple instances of an object/class

    Hello, so I have an application where 2 players can enter into a 1v1 and then before the 1v1 starts they have 1 minute to bet a certain amount of money based off how much they think they will win, so there can be multiple 1v1's happening at one time so I need to be able to keep track of all the players and the amount of money they bet so that the winner can receive all the money.

    So I determined that the best way to do this was to create a 1v1 class but I do not know how I would keep track of all the different 1v1's going on at one time, when a player adds a bet, I need to be able to find the correct 1v1 (that contains the 2 players name) and increase the bet amount for that bet and not everyone's bet. And when 1 player dies I need to be able to find the correct instance of the class that contains that player's name.

    Right now I have it so when a player accepts a 1v1 request it passes the following data to the class

    Java Code:
    OneVsOne ovo = new OneVsOne(p1, p2, betting);
    And then I would call a specific class inside the "OneVsOne" class

    Java Code:
    ovo.randomClass();
    (betting would default to 0 since there has not been any bets placed). But when a player does bet I need to pass to the class that contains player 1 and player 2 the value of betting, I'm confused how I would do this.

    Thanks,
    Ethan

    (Also I have no idea if this would belong in 'Advanced java' or not) :\

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: How to get multiple instances of an object/class

    Quote Originally Posted by xEthan View Post
    (Also I have no idea if this would belong in 'Advanced java' or not) :\
    No, all homework belongs in New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,712
    Rep Power
    5

    Default Re: How to get multiple instances of an object/class

    So basically you don't know how to set a value in an object.

    Well, then its time to open up your Java book and start at chapter one.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    xEthan is offline Member
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default Re: How to get multiple instances of an object/class

    I understand how to pass values to an object, but for all I know there could be 1 of these objects called, or 100. So I need to know how to figure out which object instance I have to use.

    So there would be multiple instances of the same object, is it possible to iterate through all of the instances and check which contains which values?
    Last edited by xEthan; 08-04-2013 at 02:01 AM.

Similar Threads

  1. How to paint multiple instances of class?
    By Zigster in forum AWT / Swing
    Replies: 5
    Last Post: 05-29-2012, 04:32 PM
  2. Multiple object instances in array of objects
    By Drizzt in forum New To Java
    Replies: 6
    Last Post: 01-12-2012, 04:07 PM
  3. Multiple GUI Interface Instances
    By mutagen in forum AWT / Swing
    Replies: 2
    Last Post: 03-19-2011, 03:06 PM
  4. Replies: 16
    Last Post: 05-22-2010, 03:51 AM
  5. Problem calling multiple instances of a class
    By virex in forum New To Java
    Replies: 1
    Last Post: 03-02-2010, 03:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •