Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

COMP1406-Assignment #6 (Due: Mon. Mar 26th @12 noon) In this assignment, you wil

ID: 3737775 • Letter: C

Question

COMP1406-Assignment #6 (Due: Mon. Mar 26th @12 noon) In this assignment, you will simulate an on-line music centre called the MusicExchangeCenter where Users log in and download Songs from other user's computers. It is similar to the operation of the original Napster program that operated a few years ago where users shared songs. You won't be doing any downloading or internet programming Instead, you will just simulate what happens in real life. The assignment will give you familiarity with ArrayLists. (1) The Song/ User Classes Here are simple Song and User classes that represent a song that is available at the Music Exchange Center and a user of the Music Exchange Center that logs in to download music public elass Song I private String private String private int title artist daration: public Song) publie song String t, String a, int , int s) title ta artista daration- 60+ publie string getTitle0 return tiele) publie String getArtistOreturn artise j pablie int getDurationreturn duration J publie int getkinates i return duration/60 publie int getSeconds f return duration % 60/ publia sering costring return+titleby atist (duration/60)+(durationms 60)) FS F7 4 5

Explanation / Answer

The method addSong lets us enter a new song to the list. You need to invoke thie method explicitly;

User us=new User();

us.addSong("path_of_song");

This method enables us to get the last index position of the arraylist. You enter the path as the argument to the method and

that song path will be added to the ArrayList as a new song

public class User{

ArrayList<String> songList= new ArrayList<String>();

public static int addSong(String newSong) {

int index;

index= songList.size();

try{

songList.add(index,newSong);

return 0;

}

catch{System.out.println("Error");}

}

public String toString() { // overridding toString function so that it displays total number of songs

index= songList.size();

System.out.println("Total number of songs: %d", index);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote