Results 1 to 3 of 3
  1. #1
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default toString output problem

    I am just doing some practice, creating a small vending machine program. I have a linked list of "Items" each with a number of variables for name, price etc. I am trying to print out the contents of my linked list whilst i am testing the operations i have created in a separate file named "VendOperations"

    toString method i want to print out
    Java Code:
    public String toString()
        {
            return getClass().getName() + " " + Name + " " + ItemID + " " + Quantity + " " + Price + " " + Keypad;
        }
    An example of how i have added an item to the linked list and then the toString method being used.
    Java Code:
    vendingMachine.AddItem(new Item("Mars","0001","A1",5,50));
    
    System.out.println(vendingMachine.toString());
    The output i get is this
    Java Code:
    VendOperations@6345e044
    Not sure why it isn't printing out correctly.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,801
    Rep Power
    25

    Default Re: toString output problem

    Did you put the posted toString() method in the VendOperations class?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: toString output problem

    Quote Originally Posted by Norm View Post
    Did you put the posted toString() method in the VendOperations class?
    oops! That is why i am refreshing myself now.
    Thanks!

Similar Threads

  1. How to display toString() inside another toString()
    By SVTermiCobra in forum New To Java
    Replies: 1
    Last Post: 08-08-2012, 02:49 AM
  2. Replies: 13
    Last Post: 12-30-2011, 04:38 AM
  3. Problem with ToString list (java)
    By sirdonclemo in forum New To Java
    Replies: 3
    Last Post: 03-23-2011, 03:02 AM
  4. Replies: 2
    Last Post: 10-23-2009, 03:48 AM
  5. problem with super.tostring()
    By faw in forum Advanced Java
    Replies: 1
    Last Post: 05-01-2008, 05:27 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
  •