Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: What is wrong with my driver and or main class

  1. #1
    Sammie is offline Member
    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0

    Default What is wrong with my driver and or main class

    I am very new to java. My high school just opened up a computer science class.
    * new note: I'm sorry. The code is correctly formatted when I edit it, but when I post it, everything is pushed to the left.
    When I print it out in the terminal window I get this:
    Color: Grey
    Memory Capacity: 4
    My Songs:[Ljava.lang.String;@36fb6d

    How do I get it to print out the actual name of the songs instead of those mixed characters?
    ---here is my MyPod class

    public class MyPod
    {
    public String color;
    int memoryCapacity;
    public String [] songLibrary;
    public MyPod ()
    {
    color="";
    memoryCapacity=0;
    songLibrary = new String [3] ;
    }

    public String toString ()
    {
    return "Color: " + color+ "\nMemory Capacity: " + memoryCapacity + "\nMy Songs:"+ songLibrary;
    }

    }

    ---here is my class MyPodDriver

    public class MyPodDriver
    {
    public static void main (String[] args)
    {
    MyPod carPod = new MyPod();

    carPod.color="Grey";
    carPod.memoryCapacity=4;
    carPod.songLibrary[0]="You and Me (Flume Remix)";
    carPod.songLibrary[1]="Hanging Tree";
    carPod.songLibrary[2]="Gymnopedia";

    System.out.println(carPod);
    }
    }
    Last edited by Sammie; 12-01-2014 at 12:38 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: What is wrong with my driver and or main class

    [Ljava.lang.String;@36fb6d
    That is the String returned by a String array's toString() method.
    If you want to see the contents of the array use the Arrays class's toString() method to format the array's contents.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Sammie is offline Member
    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0

    Default Re: What is wrong with my driver and or main class

    Would you be able to provide an example please?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: What is wrong with my driver and or main class

    Did you read the API doc for the Arrays class? Do you have any questions about the method?
    Or do a Search here on the forum for samples.
    DarrylBurke likes this.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 11
    Last Post: 10-30-2012, 10:28 AM
  2. Replies: 0
    Last Post: 03-03-2012, 02:01 AM
  3. Replies: 6
    Last Post: 02-08-2012, 07:42 PM
  4. What wrong with it?case : public static void main
    By bytescode in forum New To Java
    Replies: 7
    Last Post: 02-10-2011, 08:01 AM
  5. Running main method class from another main class
    By tlrocketman in forum New To Java
    Replies: 3
    Last Post: 12-06-2010, 09:30 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
  •