Aw

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Aw as PDF for free.

More details

  • Words: 149
  • Pages: 2
import java.util.*; import java.io.*; class Song { String title; String artist; Song(String t,String a) { title=t; artist=a; } public String getTitle() { return title; } public String getArtist() { return artist; } public String toString() { return title+":"+artist; } } public class Jutebox2 { ArrayList<Song> songList=new ArrayList<Song>(); public static void main(String f[]) { new Jutebox1().go(); } class ArtistCompare implements Comparator<Song> { public int compare(Song one,Song two) { return(one.getArtist().compareTo(two.getArtist())); } } class TitleCompare implements Comparator<Song> { public int compare(Song one,Song two) { return(one.getTitle().compareTo(two.getTitle())); } } public void go() {

getSongs(); System.out.println(songList); System.out.println("By artist :\n"); ArtistCompare ac=new ArtistCompare(); Collections.sort(songList,ac); System.out.println(songList); System.out.println("By title :\n"); TitleCompare tc=new TitleCompare(); Collections.sort(songList,tc); System.out.println(songList);

}

//HashSet<Song> songList1=new HashSet<Song>(); //songList1.addAll(songList); //System.out.println("by using hashset.........."); //System.out.println(songList1);

void getSongs() { try { File f=new File("SongList.txt"); BufferedReader reader=new BufferedReader(new FileReader(f)); String line=null; while((line=reader.readLine())!=null) { addSongs(line); } } catch(Exception e){} }

}

void addSongs(String linetoparse) { String[] tokens=linetoparse.split("/"); Song nextSong=new Song(tokens[0],tokens[1]); songList.add(nextSong); }

Related Documents

Aw
May 2020 22
Aw!~
November 2019 38
Aw
November 2019 31
Aw Peloponnesianwar
May 2020 0
Collection Aw
May 2020 1
Kohhran Aw
June 2020 6