Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String author;
- private String name;
- private String year;
- public Album(String a, String n, String y) { // constructor
- author = a;
- name = n;
- year = y;
- }
- public String toString()
- {
- return author +","+ name + "," + year;
- }
- public int compareTo(Album a) {
- // usually toString should not be used,
- // instead one of the attributes or more in a comparator chain
- return toString().compareTo(a.toString());
- }
- public Album collection[]= new Album[10];
- private int numAlbums = 0;
- public void Add (Album a){
- if (numAlbums >= collection.length){
- Album newcollection[]= new Album [collection.length * 2];
- for (int n = 0; n < numAlbums; n ++){
- newcollection[n] = collection[n];
- }
- newcollection = collection;
- }
- collection[numAlbums] = a;
- numAlbums = numAlbums + 1;
- }
- public String toString()
- {
- String details = "";
- for ( int p = 0; p < collection.length ; p ++)
- {
- details = details + collection[p] + "n" ;
- }
- details += "n";
- return details;
- }
- public static void main(String[] args) {
- Collection c = new Collection();
- c.Add( new Album("DaftPunk","Discovery","2001"));
- c.Add( new Album ("Pink Floid","The Dark Side Of The Moon","1973"));
- c.Add( new Album( "The Clash", "London Calling", "1979"));
- System.out.print(c);
- }
Add Comment
Please, Sign In to add comment