I have a program that has 2 options. 1;to read a file and 2, to add a file:
The text file looks like this word for word:
Yellow Submarine
Beatles
Rock
Welcome to my life
Simple plan
Alternative
Break
Three Days Grace
Rock
There are 9 files and 3 arrays. One for songs, one for artists and one for genre
the count is declared like this:
int[] count = {0};
NOW... If the user reads the program, then adds a file and then reads it again it will look like this:
Yellow Submarine
Beatles
Rock
Welcome to my life
Simple plan
Alternative
Break
Three Days Grace
Rock
NewSong
NewArtist
NewCateg
Yellow Submarine
Beatles
Rock
Welcome to my life
Simple plan
Alternative
Break
Three Days Grace
Rock
NewSong
NewArtist
NewCateg
There are 24 files.... How can I fix this?
static void Read (String[] Song, String[] Artist, String[] Category, int[] count, String[] database) throws IOException //to open and view the database { BufferedReader reader = new BufferedReader (new FileReader (database [0] + ".txt")); System.out.println ("Here is your music collection: "); // System.out.println ("First is a song, followed by the artist and last is the category: "); String line = null; while ((line = reader.readLine ()) != null) { Song [count [0]] = (line); line = reader.readLine (); Artist [count [0]] = (line); line = reader.readLine (); Category [count [0]] = (line); count [0]++; } reader.close (); System.out.println ("Song" + " " + "Artist" + " " + "Category"); // spacing is correct System.out.println (); for (int i = 0 ; i < count [0] ; i++) { System.out.print (Song [i]); for (int j = 0 ; j < (30 - Song [i].length ()) ; j++) System.out.print (' '); System.out.print (Artist [i]); for (int j = 0 ; j < (30 - Artist [i].length ()) ; j++) System.out.print (' '); System.out.print (Category [i]); for (int j = 0 ; j < (29 - Category [i].length ()) ; j++) System.out.print (' '); System.out.println (' '); } System.out.println ("There are: " + count [0] + " songs");