i am new to java, and would like some advice on the following
i have two files:
SongsList.java and SongsMenu.java
SongsMenu.java (http://pastie.org/private/cm0zpembkqnfjif0pgdadq) lines 38 / 39
import java.util.Scanner;
import java.util.InputMismatchException;
public class SongsMenu {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
...
switch (listMenuItem) {
case 1:
System.out.println("Album");
SongsList sl = new SongsList();
System.out.println(sl);
break;
and SongsList.java (http://pastie.org/private/qljonhfdronvbq4ahcqgmq)
public class SongsList {
public static void main(String args[]) throws Exception {
// reads the file and returns a list of my Music.txt file
...
when i run the SongsList, i get:
$java SongsList
Track 58 Reggae 1637918 81 58 59 18/02/2010 21:02 28/01/2012 14:07 160 44100 MPEG audio file khinester:Users:khinester:Music:iTunes:iTunes Music:Unknown Artist:Unknown Album:58 Track 58.mp3
Track 59 Reggae 4239191 211 59 59 18/02/2010 21:02 28/01/2012 14:07 160 44100 MPEG audio file khinester:Users:khinester:Music:iTunes:iTunes Music:Unknown Artist:Unknown Album:59 Track 59.mp3
...
but when i run the SongsMenu
$java SongsMenu
1) Album
...
1
Album
SongsList@50ef5502
How do i return the list, instead of ‘SongsList@50ef5502’ i would like to ultimately be able to list this in order of Album, Name and make searches.
Any advice much appreciated.
The problem is with this line
If you try to print an object, it will only print the hashcode of the given object.
Better rewrite the program as further explained:
You can move you logic into a method and explictly call the method (or move the logic into default contructor), for example:
SonglistClass should be like this:And call songlist in songsmenu like this:
Hope this will help you. Better learn some OOP concepts buddy… It is bad to have doubts in such a basic Java code.
Try to learn java from Head first java book: Head First Java.pdf
It is quite simple and fun to learn it.