Sunday, November 30, 2014

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);

}

}



No comments:

Post a Comment