Advertisement
Guest User

CutupSongCreator

a guest
Nov 17th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class CutupSongCreator {
  5. //extends Object;
  6.  
  7.     public static void main(String[] args) {
  8.         System.out.println("Filename? ");
  9.         Scanner reader = new Scanner(System.in);
  10.         String filename = reader.nextLine();
  11.        
  12.         try {
  13.             reader = new Scanner(new File(filename));
  14.         } catch (FileNotFoundException e) {
  15.         System.out.println("The file named " + filename + " cannot be found.");
  16.         }
  17.        
  18.         SongLine[] songs = makeArray(reader);
  19.         printArray(songs);
  20.        
  21.         reader.close();
  22.     }
  23.    
  24.     public static void printArray(SongLine[] songs) {
  25.         for(SongLine song : songs) {
  26.             System.out.println(song.toString());
  27.         }
  28.     }
  29.    
  30.     public static SongLine[] makeArray(Scanner reader) {
  31.         SongLine[] bowieSong = null; //songs
  32.         int count = -1;
  33.        
  34.         while (reader.hasNext()) {
  35.             if (count < 0) {
  36.                 bowieSong = new SongLine[Integer.parseInt(reader.next())];
  37.             }
  38.             String[] frag = reader.nextLine().split("\\t");
  39.             if (count > -1 && bowieSong != null && frag.length == 3) {
  40.                 bowieSong[count] = new SongLine(frag[0], Integer.parseInt(frag[1]), frag[2]);
  41.             }
  42.             count++;
  43.         }
  44.         return bowieSong;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement