loops - create a jukebox program in java -
i creating program create jukebox play selection of music have list of songs , user picks song listen to. however, confused on supposed code jukebox class. juke box class supposed implementation class display menu , play music. having hard time figuring out how program way. if me or guide me through amazing! thank you
my code far:
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 class jukebox { } 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); } }
and result of program should this:
public string displaymenu(){ for(string s : filelist) { system.out.println(s); } scanner in = new scanner(system.in); system.out.print("what song want listen ? "); string songname = in.nextline(); return songname } public void displaymenu(string songname){ ...your here ... }
Comments
Post a Comment