import java.io.File; import java.io.FileNotFoundException; import java.util.HashSet; import java.util.Scanner; public class Spotify { public static void main(String[] args) { HashSet sanger = new HashSet<>(); Scanner sc = null; try { sc = new Scanner(new File("sanger.txt")); } catch (FileNotFoundException e) { System.out.println("Fil ikke funnet"); System.exit(1); } while (sc.hasNextLine()) { String[] line = sc.nextLine().split(";"); Sang sang = null; String tittel = line[1]; String artist = line[2]; int lengde = Integer.parseInt(line[3]); String url = line[4]; switch (line[0]) { case "Jazz": sang = new JazzSang(tittel, artist, lengde, url); break; case "Pop": boolean dansbar = Boolean.parseBoolean(line[5]); sang = new PopSang(tittel, artist, lengde, url, dansbar); break; // Gj?r noen endringer case "Eksperimentell": if (line.length > 5) { HashSet features = new HashSet<>(); for (int i = 5; i < line.length; i++) { features.add(line[i]); } sang = new EksperimentellHipHopSang(tittel, artist, lengde, url, features); } else { sang = new EksperimentellHipHopSang(tittel, artist, lengde, url); } break; case "LostMedia": int funnetAar = Integer.parseInt(line[4]); sang = new LostMedia(tittel, artist, lengde, funnetAar); break; case "Trap": sang = new TrapSang(tittel, artist, lengde, url); default: } sanger.add(sang); } sc.close(); for (Sang s : sanger) { // Kun spillbare sanger skal spilles if (s instanceof Spillbar) { Spillbar s2 = (Spillbar) s; s2.spill(); } else if (s instanceof LostMedia) { LostMedia s2 = (LostMedia) s; s2.analyser(); } if (s instanceof PopSang) { PopSang s2 = (PopSang) s; if (s2.harSTANs()) { System.out.println("Sangen har mange stans\n"); } else { System.out.println("Ingen kjenner denne sangen\n"); } } } for (Sang sang : sanger) { System.out.println(sang); } // Teste equals PopSang tmf = new PopSang("That's My Floor", "Magdalena Bay", 209, "url", true); JazzSang tmf2 = new JazzSang("That's My Floor", "Magdalena Bay", 209743, "url"); System.out.println(tmf.equals(tmf2)); // Teste remix TrapSang trapsang = new TrapSang("My Eyes", "Travis Scott", 251, "url"); trapsang.spill(); HashSet ft = new HashSet<>(); try { trapsang.remix(ft); } catch (IngenFeaturesRuntimeException e) { e.printStackTrace(); System.exit(1); } System.out.println("Hello world"); } }