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: Help with conversion

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help with conversion

    Okay, I need to read in a variable from a user for an object which I defined, called CatalogItem. I don't know how I can convert the String which I read in from the user into a CatalogItem object.
    				System.out.print("Enter the name of desired CatalogItem to add: ");
    				temp = scan.next();
    				CatalogItem newItem = CatalogItem(temp);
    is there a way to use the String value that I read from the keyboard, "temp", as an identifier of a CatalogItem object. What I mean is CatalogItem temp.
    Last edited by TheEvilCouncil; March 2nd, 2012 at 05:53 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,104
    Thanks
    48
    Thanked 2,153 Times in 2,126 Posts

    Default Re: Help with conversion

    how I can convert the String which I read in from the user into a CatalogItem object
    You can't directly. You can create an instance of the CatalogItem class and pass it the String in its constructor.

    a way to use the String value that I read from the keyboard, "temp", as an identifier of a CatalogItem object
    One way would be to use a Map object where the String is the key and the CatalogItem object is the value.

  3. The Following User Says Thank You to Norm For This Useful Post:

    TheEvilCouncil (March 2nd, 2012)

Similar Threads

  1. Base Conversion
    By Pingu in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 22nd, 2011, 02:15 PM
  2. BASE CONVERSION
    By bgwilf in forum Algorithms & Recursion
    Replies: 6
    Last Post: November 13th, 2010, 11:02 AM
  3. JAVA to C++ conversion
    By hackerboy101 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 28th, 2010, 08:31 PM
  4. Explicit Conversion?
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 11th, 2009, 10:40 PM
  5. binary conversion..
    By chronoz13 in forum Java Theory & Questions
    Replies: 8
    Last Post: September 16th, 2009, 10:47 AM