-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicLibraryUI.java
More file actions
68 lines (60 loc) · 1.81 KB
/
MusicLibraryUI.java
File metadata and controls
68 lines (60 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.Scanner;
import java.util.ArrayList;
public class MusicLibraryUI{
private static Scanner s = new Scanner(System.in);
public static void printFirst(){
System.out.print("Enter `D` to read the music file from your local disk or `W` to read the music file from the web: ");
}
public static void printSecond(){
System.out.print("Enter `A` to output tracks by Artists or `T` to output tracks by Title. Enter `Q` to quit: ");
}
public static String getFirstCommand() {
while(true) {
String command = s.nextLine();
if(command.equalsIgnoreCase("w") || command.equalsIgnoreCase("d")){
return command;
}
System.out.println("Invalid Input.");
printFirst();
}
}
private static void outputToFile(String choice, ArtistBucket artistList, TitleBucket tracksList){
// if choice A output artistOutput.txt
OutputFile outputFile = new OutputFile();
ArrayList<ArrayList<MusicTrack>> outputBucket;
if(choice.equalsIgnoreCase("a")){
outputFile.open("artistOutput.txt");
outputBucket = artistList.getBuckets();
}
else{
outputFile.open("titleOutput.txt");
outputBucket = tracksList.getBuckets();
}
for(int i = 0; i < outputBucket.size(); i++){
ArrayList<MusicTrack> tracks = outputBucket.get(i);
for(int j = 0; j < tracks.size(); j++){
outputFile.writeItem(tracks.get(j));
}
}
outputFile.close();
}
public static void getSecondCommand(ArtistBucket artistList, TitleBucket tracksList) {
while(true) {
String command = s.nextLine();
if(command.equalsIgnoreCase("a") || command.equalsIgnoreCase("t")){
outputToFile(command, artistList, tracksList);
printSecond();
}
else if(command.equalsIgnoreCase("q")){
break;
}
else{
System.out.println("Invalid Input.");
printSecond();
}
}
}
public static void closeScanner(){
s.close();
}
}