vendredi 19 juin 2015

creating a jukebox program

I am creating a jukebox program where I create a list of songs and input the user to pick a song to play. I am using java to write this and am creating a separate implementation class and tester class. I am having a hard time with the implementation class. My teacher has given me notes(the lines with the // in my program) to guide me on what to do, but I cant seem to get it. I have tried but I am not getting it and cant figure out how to get it to work. I don't think I displayed the menu correctly or allowed the user to input a song correctly.

My overall output that displays the menu of songs and ask the user to choose a song should look like this(the lines with // are what I am supposed to do in the section):

output of songs

My implementation class that I am struggling with is:

import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class JukeBox 
{
    //Private Instance Variables (playList and fileList)
    private String[] playList;
    private String[] fileList;

    public JukeBox() {
        //initialize your private instance variables (playList and fileList)
        String playList = "";
        String fileList = "";
    }

    public static int displayMenu()
    {
     // Print out the menu from the text file (you are passing in PlayList and FileList in the constructor
     System.out.println("PlayList.txt");
     System.out.println("Enter your choice(1-3)");
     // Return the user choice back to the main() method in JukeBoxTester
     return choice;
     }

    public void playSong(int choice)
    {
        //This will play the song based on what the user entered in displayMenu.  The choice is passed into playSong() from the main() method.
        userInput.play();
    }  

     public static void main(String[] args) throws IOException
    {
     String userInput = "";

     File fileName = new File("PlayList.txt");
     Scanner inFile = new Scanner(fileName);
     Scanner in = new Scanner(System.in);

     if(userInput.equals(1))
     {
         SimpleSound song1 = new SimpleSound("Twist And Shout.wav");
         song1.play();
     }

     if(userInput.equals(2)){
         SimpleSound song2 = new SimpleSound("Born to Be Wild.wav");
         song2.play();  
     }    

     if(userInput.equals(3)){
         SimpleSound song3 = new SimpleSound("I Walk the Line.wav");
         song3.play();  
     }
   }  
}  

And then my tester program is this in case you would like to see it as well:

import java.util.Scanner;
import java.io.File;
import java.io.IOException;
class FileHandler
{
    private String[] playList = new String[3];
    private String[] fileList = new String[3];
    private String file;

    FileHandler(String f) 
    {
        file = f;
    }

    public void readFile() throws IOException
    {
        int index = 0;
        File fileName = new File(file);
        Scanner inFile = new Scanner(fileName);
        while (inFile.hasNext())
        {
            playList[index] = inFile.nextLine();
            fileList[index] = inFile.nextLine();
            index++;
        }
        inFile.close();
    }

    public String[] getPlayList()
    {
        return playList;
    }

    public String[] getFileList()
    {
        return fileList;
    }
 }//end of class 


public class JukeBoxTester
{
    public static void main(String[] args) throws IOException
    {
        int choice = 0;
        FileHandler fileHandler = new FileHandler("PlayList.txt");
        fileHandler.readFile();
        String [] playList = fileHandler.getPlayList();
        String [] fileList = fileHandler.getFileList();

        JukeBox myPod = new JukeBox(playList, fileList);
        choice = myPod.displayMenu();
        myPod.playSong(choice);

    }
}

Thank you so much for helping

Aucun commentaire:

Enregistrer un commentaire