Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class CutupSongCreator {
- //extends Object;
- public static void main(String[] args) {
- System.out.println("Filename? ");
- Scanner reader = new Scanner(System.in);
- String filename = reader.nextLine();
- try {
- reader = new Scanner(new File(filename));
- } catch (FileNotFoundException e) {
- System.out.println("The file named " + filename + " cannot be found.");
- }
- SongLine[] songs = makeArray(reader);
- printArray(songs);
- reader.close();
- }
- public static void printArray(SongLine[] songs) {
- for(SongLine song : songs) {
- System.out.println(song.toString());
- }
- }
- public static SongLine[] makeArray(Scanner reader) {
- SongLine[] bowieSong = null; //songs
- int count = -1;
- while (reader.hasNext()) {
- if (count < 0) {
- bowieSong = new SongLine[Integer.parseInt(reader.next())];
- }
- String[] frag = reader.nextLine().split("\\t");
- if (count > -1 && bowieSong != null && frag.length == 3) {
- bowieSong[count] = new SongLine(frag[0], Integer.parseInt(frag[1]), frag[2]);
- }
- count++;
- }
- return bowieSong;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement