Results 1 to 6 of 6
  1. #1
    monkeyhead is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Question Creating an object based on user input parameters

    Hi there,

    This is what I'm trying to do:-

    Create a player object based on user input
    Remove player based on user input

    This is what I've tried:

    Createing a switch, one case for adding and another for removing.

    The Problem I'm hitting:-

    If I place the constructor for player in the switch case I can only use it in that particular case,like wise out side of the switch. But the player needs to be created based on the user input, such as name etc. And if I want to remove the player I enter the players details , checks if it exists and if it does removes it from my set.

    Any advice would be much appreciated!

    Many thanks

    Monkeyhead

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Creating an object based on user input parameters

    Your question is very vague. Where do you store the Player object once it has been created?

  3. #3
    monkeyhead is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Creating an object based on user input parameters

    In a hashset in the team class.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Creating an object based on user input parameters

    Java Code:
    create temp Player object
    if creating {
        add temp Player to HashSet
    } else if deleting {
        remove temp Player from HashSet
    } else {
        invalid choice
    }

  5. #5
    monkeyhead is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Creating an object based on user input parameters

    Thanks, so its not possible with a switch then?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Creating an object based on user input parameters

    Sure, a switch in general can replace an if statement. It depends upon what you are trying to switch on.

Similar Threads

  1. Displaying a square based on user's input
    By luke in forum New To Java
    Replies: 15
    Last Post: 07-14-2012, 10:43 AM
  2. How do I retrieve data based on user input?
    By tunali2 in forum New To Java
    Replies: 1
    Last Post: 04-03-2011, 03:40 PM
  3. Creating a number of objects based on user input.
    By Kevinius in forum New To Java
    Replies: 21
    Last Post: 04-03-2011, 09:53 AM
  4. Dynamic Create Object based on user's input?
    By diskhub in forum New To Java
    Replies: 2
    Last Post: 03-08-2011, 05:47 PM
  5. Replies: 2
    Last Post: 01-13-2011, 06:43 AM

Posting Permissions

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