From 5a3bf67e1c8613192540f73c791d3482898fb994 Mon Sep 17 00:00:00 2001 From: orange Date: Wed, 28 Dec 2016 12:54:45 +0100 Subject: [PATCH] Radio --- src/Radio/Canzone.java | 4 ++++ src/Radio/LibreriaCanzoni.java | 8 ++++++-- src/Radio/Test.java | 17 +++++++++++++++++ src/Radio/lib.dat | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/Radio/Test.java create mode 100644 src/Radio/lib.dat diff --git a/src/Radio/Canzone.java b/src/Radio/Canzone.java index 292d199..3f97540 100644 --- a/src/Radio/Canzone.java +++ b/src/Radio/Canzone.java @@ -20,6 +20,10 @@ public class Canzone{ return album; } + public String toString(){ + return titolo+" "+autore+" "+album+"."; + } + public static Canzone read(Scanner sc){ String titolo, autore, album; if(!sc.hasNext()) return null; diff --git a/src/Radio/LibreriaCanzoni.java b/src/Radio/LibreriaCanzoni.java index 2b32008..9bf1e35 100644 --- a/src/Radio/LibreriaCanzoni.java +++ b/src/Radio/LibreriaCanzoni.java @@ -17,6 +17,10 @@ public class LibreriaCanzoni{ this.lib=lib; } + public LinkedList getLib(){ + return lib; + } + public LibreriaCanzoni filtroAutore(String autore){ LinkedList newLib = new LinkedList(); ListIterator iter = lib.listIterator(); @@ -29,7 +33,7 @@ public class LibreriaCanzoni{ return new LibreriaCanzoni(newLib); } - public LibreriaCanzoni filtroTitolo(String titolo){ + public LibreriaCanzoni filtroTitolo(String titolo){ LinkedList newLib = new LinkedList(); ListIterator iter = lib.listIterator(); while(iter.hasNext()){ @@ -41,7 +45,7 @@ public class LibreriaCanzoni{ return new LibreriaCanzoni(newLib); } - public LibreriaCanzoni filtroAlbum(String album){ + public LibreriaCanzoni filtroAlbum(String album){ LinkedList newLib = new LinkedList(); ListIterator iter = lib.listIterator(); while(iter.hasNext()){ diff --git a/src/Radio/Test.java b/src/Radio/Test.java new file mode 100644 index 0000000..9ecb7bd --- /dev/null +++ b/src/Radio/Test.java @@ -0,0 +1,17 @@ +import java.util.LinkedList; +import java.util.ListIterator; +import java.util.Scanner; +import java.io.File; + +public class Test{ + public static void main(String [] args) throws Exception{ + Scanner sc = new Scanner(new File("lib.dat")); + LibreriaCanzoni radio=new LibreriaCanzoni(sc); + + ListIterator iter = radio.filtroAutore("Green Day").getLib().listIterator(); + + while(iter.hasNext()){ + System.out.println(iter.next().toString()); + } + } +} \ No newline at end of file diff --git a/src/Radio/lib.dat b/src/Radio/lib.dat new file mode 100644 index 0000000..41dbb27 --- /dev/null +++ b/src/Radio/lib.dat @@ -0,0 +1,20 @@ +Secchio +Pop x +Lesbianitj +# +Minority +Green Day +International Superhits +# +21 Guns +Green Day +21 Guns +# +Sparami +Pop x +Lesbianitj +# +Melons +Pop x +Lesbianitj +# \ No newline at end of file