0

How do i add an array in a file menu, the code below lets me input 10 artists and 10 songs for each artist.

import java.io.*;
public class Music {

    public static void main(String[] args) throws IOException
    {
        BufferedReader stuff = new BufferedReader(new InputStreamReader(System.in));
        String inData;
        int [] [] MUSIC = new int [2] [10];
        for (int counter = 0; counter <= 1; counter++)
        {
            System.out.print( "Enter Artist: ");
            inData = stuff.readLine();

            for (int index = 0; index<=9 ;index++)
            {
                System.out.print( "Enter Record: ");
                inData = stuff.readLine();

            }
        }
        System.out.println( "Below is a printout");

        for (int counter = 0; counter <= 20; counter++)
        {
            System.out.print("The nos on Row "+ counter + " are ");
            for (int index = 0; index<= 20;index++)
            {

            }
            System.out.println();
        }
    }
}

I believe that i need to put something like case 1 here and maybe have the code to write the file in a class above the main.

maba
  • 47,113
  • 10
  • 108
  • 118

2 Answers2

0

The simplest way is to redirect System.out to a file on the command line. Alternatively you could reassign System.out in your code or better still do some file I/O - all of these have been discussed here System.out to a file in java

Community
  • 1
  • 1
Dave Richardson
  • 4,880
  • 7
  • 32
  • 47
0

You are not really storing the entire artists name in the array. Here is one way you can do this.

  1. Create 2 String Arrays. One for the artist name and the second(multi dimensional) for the tracks.

  2. For each index, store the fetched artist name in the 1st array and the track in the second array for the same index.

  3. Fetch the data from the 2 arrays using the lopp that you have written and write it to a file using one of the different approaches mentioned in this thread
Community
  • 1
  • 1
Adarsh
  • 3,613
  • 2
  • 21
  • 37