Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5 Split the CSV string into data values
- 1. Create a new class called Track in a new tab. Name the tab Track.java. This will
- make it a java file.
- 2. Give your Track class three variables and a constructor as follows:
- 1 class Track {
- 2 private String title ;
- 3 private String artist ;
- 4 private String len ;
- 5
- 6 public Track ( String t, String a, String l) {
- 7 title = t;
- 8 artist = a;
- 9 len = l;
- 10 }
- 11 }
- 3. In your setup, inside the while statement and after you read the line of text, declare a
- local variable of type String[] (array of string) and call it data.
- 4. Assign a value to data by using the split function on your csv variable to split the
- string on every comma:
- 1 data = csv. split (",");
- 5. Declare a local variable of type Track called track. Assign it a value by calling the
- Track constructor, passing the three values in your array as parameters to the
- constructor. Note that data[0] holds the title, data[1] holds the artist, and so on.
- 6. Add a println statement to print the value of track.
- Run your program. You should see some output in the console like this
- Track@d0c2d92
- Track@944c285
- Track@6219c2e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement