Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-14-2011, 11:24 PM   PM User | #1
0c0de
New to the CF scene

 
Join Date: Feb 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
0c0de is an unknown quantity at this point
One Vector two Jlist's

I have this assignment due and having trouble with the list's, the assignment is to take these file names and split them into two list one being artist names and the other song titles. I've managed to split them, but the the artist name either shows on both lists ore both the artist and song title are on the same list or on both list's. Here some of my sample code any suggestions would mean a lot.

Code:
...
    private Vector<String>  items;

    private static String   artists = "Artist";
    private static String   title = "Title";

    public jTune_Gui(){
        this(new Vector<String>());
    }

    public jTune_Gui(Vector<String> listEntries){
        super("Nahid's jTunes Browser");
        items = listEntries;
        intializeComponents();

         jOpenButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jOpenButtonEventHandler();
            }
        });

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        update();

    }

     private void intializeComponents(){ some code ..}
     private void jOpenButtonEventHandler(){ some code ...}
     private void update(){
        jArtistList.setListData(items);
       // jSongsList.setListData(items);
    }

    private void traverse(File fileOrDir){
        if(fileOrDir.isDirectory()){
            File[] kid = fileOrDir.listFiles();
            for(int i = 0; i < kid.length; i++){
                traverse(kid[i]);
            }

        }else{
            String fileName = fileOrDir.getName();

            StringTokenizer tokens = new StringTokenizer(fileName);

            boolean firstDashFound = false;
            boolean secondDashFound = false;
            String songTitle = "";
            String artist = "";

            while(tokens.hasMoreElements()){
                String aWord = tokens.nextToken();
                if(firstDashFound && !secondDashFound && !aWord.equals("-"))
                    artist = artist + aWord + " ";
                if(secondDashFound) songTitle = songTitle + aWord + " ";
                if(aWord.equals("-")){
                    if(firstDashFound) secondDashFound = true;
                    firstDashFound = true;
                }
            }
            String newSongTitle = "";
            boolean dotFound = false;
            for(int i = 0; i < songTitle.length(); i++){
                if(songTitle.charAt(i) == '.') dotFound = true;
                if(!dotFound) newSongTitle = newSongTitle + songTitle.charAt(i);
            }
            String newArtistName = artist.trim();

            Song sonG = new Song(newSongTitle, newArtistName);

          //  items.add(sonG.getSongTitle());
            items.add(sonG.getArtist());
        }
    }
   
}
0c0de is offline   Reply With Quote
Old 03-15-2011, 01:13 AM   PM User | #2
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
What is your input to this? Is it like

Code:
-Aradon Rocker - "Sometimes I'm awesome"
Or is it like

Code:
  Aradon Rocker - "Sometimes I'm awesome" -
Or is it like

Code:
  Aradon Rocker - - "Sometimes it hurts to be so awesome"
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Old 03-15-2011, 03:05 AM   PM User | #3
0c0de
New to the CF scene

 
Join Date: Feb 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
0c0de is an unknown quantity at this point
The input's like this

Code:
01 - infected mushroom - cities of the future - radio edit.txt
0c0de is offline   Reply With Quote
Old 03-15-2011, 07:48 PM   PM User | #4
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Can you give us an example of when it doesn't work?

Here is the code I wrote and it's outputs:

Code:
import java.util.*;

public class testCodingforums {

	public static void main (String args[])
	{
		String fileName = "01 - infected mushroom - cities of the future - radio edit.txt";

        StringTokenizer tokens = new StringTokenizer(fileName);

        boolean firstDashFound = false;
        boolean secondDashFound = false;
        String songTitle = "";
        String artist = "";

        while(tokens.hasMoreElements()){
            String aWord = tokens.nextToken();
            if(firstDashFound && !secondDashFound && !aWord.equals("-"))
                artist = artist + aWord + " ";
            if(secondDashFound) songTitle = songTitle + aWord + " ";
            if(aWord.equals("-")){
                if(firstDashFound) secondDashFound = true;
                firstDashFound = true;
            }
        }
        String newSongTitle = "";
        boolean dotFound = false;
        for(int i = 0; i < songTitle.length(); i++){
            if(songTitle.charAt(i) == '.') dotFound = true;
            if(!dotFound) newSongTitle = newSongTitle + songTitle.charAt(i);
        }
        String newArtistName = artist.trim();
        
        System.out.println(newArtistName);
        System.out.println(newSongTitle);
	}
}
Code:
Outputs: 

infected mushroom
cities of the future - radio edit
So it looks like your looping is pretty sound given the input you've given us. Maybe your outputting is wrong?
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:00 AM.


Advertisement
Log in to turn off these ads.