Created
June 5, 2018 16:54
-
-
Save enseitankad0/81666a3c8905f5be6ae5551eae681fbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.enseitankad0; | |
import com.enseitankad0.model.*; | |
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Datasource datasource = new Datasource(); | |
if (!datasource.open()) { | |
System.out.println("Can't open datasource"); | |
return; | |
} | |
List<Artist> artists = datasource.queryArtists(5); | |
if (artists == null) { | |
System.out.println("No artists!"); | |
return; | |
} | |
LinkedList<Song> playList = new LinkedList<>(); | |
ListIterator<Song> listIterator = playList.listIterator(); | |
HashMap<Integer,Song> playList2 = new HashMap<>(); | |
int keyInt = 1; | |
boolean quit = false; | |
boolean forward = true; | |
while (!quit) { | |
printMenu(); | |
Scanner scanner = new Scanner(System.in); | |
int action = scanner.nextInt(); | |
scanner.nextLine(); | |
switch (action) { | |
case 1: | |
System.out.println(" ### ARTISTS LIST ### "); | |
printArtists(artists); | |
quit = false; | |
//printMenu(); | |
break; | |
case 2: | |
System.out.println("Which artist do you want to check?"); | |
int choice = scanner.nextInt(); | |
scanner.nextLine(); | |
List<SongArtist> songs = datasource.queryEverything(choice, 1); | |
for (SongArtist song : songs) { | |
System.out.println(song.toString()); | |
} | |
break; | |
case 3: | |
System.out.println("Add song to playlist by ID. Type it. Type 0 to finis"); | |
boolean finished = false; | |
ArrayList<Integer> songsID = new ArrayList<>(); | |
while (!finished) { | |
int songID = scanner.nextInt(); | |
scanner.nextLine(); | |
if (songID == 0) { | |
finished = true; | |
continue; | |
} | |
songsID.add(songID); | |
} | |
System.out.println("You choosed song numbers"); | |
List<Song> songArtists = new ArrayList<>(); | |
for (Integer number : songsID) { | |
System.out.print(number + ", "); | |
songArtists.add(datasource.queryArtistsForSong(number)); | |
} | |
System.out.println(String.format("|%1$-5s|%2$-40s|%3$-30s|%4$-30s", "ID", "Song title", "Album name", "Artist name")); | |
System.out.println("-------------------------------------------------------------------------------------------"); | |
for (Song song : songArtists) { | |
System.out.println(song.toString()); | |
playList.add(song); | |
playList2.put(keyInt,song); | |
keyInt++; | |
} | |
break; | |
case 4: | |
printList(playList); | |
break; | |
case 5: | |
// System.out.println("NOW PLAYING"); | |
// System.out.println(playList2.get(1).toString()); | |
if (!forward) { | |
if (listIterator.hasNext()) { | |
listIterator.next(); | |
} | |
forward = true; | |
} | |
if (listIterator.hasNext()) { | |
System.out.println("Now playing " + listIterator.next()); | |
} else { | |
System.out.println("We have reached the end of the playlist"); | |
forward = false; | |
} | |
break; | |
} | |
} | |
datasource.close(); | |
} | |
public static void printArtists(List<Artist> artists) { | |
for (Artist artist : artists) { | |
String name = artist.getName(); | |
System.out.format("%1$-40s ID: %2$5s", name, artist.getId() + "\n"); | |
} | |
} | |
private static void printMenu() { | |
System.out.println("Available actions:\npress"); | |
System.out.println("0 - to quit\n" + | |
"1 - To show artists list\n" + | |
"2 - to check all songs of specified Artist\n" + | |
"3 - Add songs to playlist\n" + | |
"4 - list songs in the playlist\n" + | |
"5 - play song\n" + | |
"6 - delete current song from playlist"); | |
} | |
private static void printList(LinkedList<Song> playList) { | |
Iterator<Song> iterator = playList.iterator(); | |
System.out.println("========= PLAYLIST ============================================= "); | |
System.out.println(String.format("|%1$-5s|%2$-40s|%3$-30s|%4$-30s", "ID", "Song title", "Album name", "Artist name")); | |
System.out.println("-------------------------------------------------------------------------------------------"); | |
while (iterator.hasNext()) { | |
System.out.println(iterator.next()); | |
} | |
iterator.remove(); | |
System.out.println("================================================================"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment