Advertisement
Guest User

Untitled

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