Question

Write a review on code below. The primary areas to focus on when doing a code...

Write a review on code below. The primary areas to focus on when doing a code review include the following: General Unit Testing, Comment and Coding Conventions, Error Handling, Resource Leaks, Performance, Functionality, and Security

Code:

package snhu.student.playlists;

import snhu.jukebox.playlist.PlayableSong;

import snhu.jukebox.playlist.Song;

import music.artist.*;

import java.util.ArrayList;

import java.util.LinkedList;

public class BrandonRickman_Playlist {

    public LinkedList<PlayableSong> StudentPlaylist(){

    

    // Creates a new array object list of playable songs

    LinkedList<PlayableSong> playlist = new LinkedList<PlayableSong>();

    

    // Creates a new call to an artist file and adds songs to play list

    ArrayList<Song> Blink182Tracks = new ArrayList<Song>();

Blink_182 b182 = new Blink_182();

Blink182Tracks = b182.getBlink_182Songs();

    

    playlist.add(Blink182Tracks.get(0));

    playlist.add(Blink182Tracks.get(2));

    

    // Creates a new call to another artist and adds songs to play list

    ArrayList<Song> GodsmackTracks = new ArrayList<Song>();

    Godsmack g = new Godsmack();

    GodsmackTracks = g.getGodsmackSongs();

    

    playlist.add(GodsmackTracks.get(0));

    playlist.add(GodsmackTracks.get(1));

    playlist.add(GodsmackTracks.get(2));

    

    // Creates a new call to another artist and adds songs to play list

    ArrayList<Song> VolbeatTracks = new ArrayList<Song>();

    Volbeat v = new Volbeat();

    VolbeatTracks = v.getVolbeatSongs();

    

    playlist.add(VolbeatTracks.get(0));

    playlist.add(VolbeatTracks.get(1));

    playlist.add(VolbeatTracks.get(2));

    

return playlist;

    }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

General Unit Testing :

Break down into method names like :

public LinkedList<PlayableSong> playlist getArtistsTracks(List<Song> tracks, int[] songIndexes){

//Add the music tracks to the playlist

}

You could write tests for this method easily and use

assertTrue(getArtistsTracks(arg1 , arg2 ), playlist.get(0));

2. Comment and Coding Convention

For Class names BrandonRickman_Playlist avoid using underscores . using camel case letters

Method name StudentPlaylist() should also have lower case letters .

3. Error Handling

The b182.getBlink_182Songs(); can return null or empty List which would throw null pointer exception .

After creating the object here -> Blink_182 b182 = new Blink_182(); , Godsmack g = new Godsmack(); , Volbeat v = new Volbeat(); check for the null exceptions .

or use Optional.of(obj).orElse(new Blink_182()); example .

Ensure PlayableSong class exists as it will throw nosuchelement Exception

4. Resource Leaks - > So far there seems to be no file handlers Input or Output file readers or writers neither database connections . No resource leaks so far.

5. Performance - LinkedList gives O(1) for insertion and deletions which seems to be used rightly when adding to PlayableSong. ArrayList gives O(1) constant time search using indexes .

6. Functionality - Achieves the desired functionality .

7. Security : Use role based access for creating and adding songs to the playlist. Use Collections.unmodifiableList(PlayLists) when storing it in the database or sending across as a stream .

Add a comment
Know the answer?
Add Answer to:
Write a review on code below. The primary areas to focus on when doing a code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help complete the items marked TODO in the code and get the tests to pass:...

    Please help complete the items marked TODO in the code and get the tests to pass: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds) // TODO (optional) refactor to DRY // TODO...

  • Please help complete the items marked TODO in the code and get the tests to pass:...

    Please help complete the items marked TODO in the code and get the tests to pass: Someone already answered it, but it was incorrect! import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestPerformance { // TODO run test and record running times for SIZE = 10, 100, 1000, 10000, ... // (choose in conjunction with REPS below up to an upper limit where the clock // running time is in the tens of seconds)...

  • JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the...

    JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...

  • THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode...

    THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers...

  • is there anyway you can modify the code so that when i run it i can...

    is there anyway you can modify the code so that when i run it i can see all the song when i click the select button all the songs in the songList.txt file can be shown song.java package proj2; public class Song { private String name; private String itemCode; private String description; private String artist; private String album; private String price; Song(String name, String itemCode, String description, String artist, String album, String price) { this.name = name; this.itemCode = itemCode;...

  • You will be building a linked list. Make sure to keep track of both the head and tail nodes.

    Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...

  • In the code below, there is a bug. please write a test case to expose the...

    In the code below, there is a bug. please write a test case to expose the bug? NOTE: We assume empty stack is a proper behavior. this behavior is it is not a bug. import java.util.ArrayList; class Stack { private int count = 0; private ArrayList stack = new ArrayList();    public void push( Object obj ) { stack.add( count++, obj ); System.out.println(count); } public Object pop() { return stack.remove( --count ); } public void push_many( Object[] obj ) {...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • Open BlueJ and create a new project (Project->New Project...). Create a new class named ListsDemo. Open the source code and delete all the boilerplate code. Type in the code to type (code to type...

    Open BlueJ and create a new project (Project->New Project...). Create a new class named ListsDemo. Open the source code and delete all the boilerplate code. Type in the code to type (code to type with bigger font) exactly as shown, filling in your name and the date in the places indicated. The code is provided as an image because you should type it in rather than copy-paste. If you need the code as text for accessibility, such as using a...

  • import java.util.List; import java.util.ArrayList; import java.util.LinkedList; public class ListPractice {       private static final int[]...

    import java.util.List; import java.util.ArrayList; import java.util.LinkedList; public class ListPractice {       private static final int[] arr = new int[100000];    public static void main(String[] args) {        for(int i=0; i<100000; i++)            arr[i] = i;               //TODO comment out this line        LinkedList<Integer> list = new LinkedList<Integer>();               //TODO uncomment this line        //List<Integer> list = new ArrayList<Integer>();               //TODO change the rest of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT