Question

(Java) Question about commenting my source code /** * Array of MP3 object which have specific...

(Java)

Question about commenting my source code

/**
 * Array of MP3 object which have specific artist as a property.
 * @param artist        name of artist
 * @param title         name of the MP3
 * @return              array of MP3 objects
 */
public MP3[] search(String artist, String title)
{ ... }

What is the search method? Does the method: public MP3[] search(String artist, String title) { ... } work?

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

public MP3[] search(String artist, String title)
   {
       // Note: at worst the maximum number of returned songs is the length of the library
       //       Inefficient. Consider using java.util.ArrayList instead.
       MP3 [] foundSongs = new MP3[library.length];
       int numFound = 0;
      
       for (int i = 0; i < library.length; i++)
       {
           MP3 current = library[i];

           String currentTitle = library[i].getTitle();

           String currentArtist = library[i].getArtist();

           if (currentTitle.equals(title) && currentArtist.equals(artist))
               foundSongs[numFound++] = current;          
       }

       if (numFound == 0)
           return null;
       return foundSongs; // Might consider using Arrays.copyOf to return a MP3[] with the correct length.
}

Add a comment
Know the answer?
Add Answer to:
(Java) Question about commenting my source code /** * Array of MP3 object which have specific...
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
  • Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact...

    Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Classics.txt (see Code Listing 7.3) from the Student Files or as directed by your instructor. Song.java is complete and will not be edited. Classics.txt is the data file that will be used by Compact Disc.java, the file you will be editing. 2. In Compact Disc.java, there are comments indicating where the missing code is to be placed. Declare...

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • In Java I am trying to search for a string in appList array and return the...

    In Java I am trying to search for a string in appList array and return the app name if found, if not return null. I have the following but get errors compiling: /*Find an app based on its name * @param name the name of the app to search for * @return the app with the given name * or null if there is no app with that name */ public App findApp(String name) { for (int i=0; i <...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

  • I have a question in how to create a method. For example there is a LinkedList...

    I have a question in how to create a method. For example there is a LinkedList of Objects, say and Object is public class Dog; private String name; private int age I want my method to take a dog age, and return the position (int) of the dog with that age has in the list example; //takes a dog age and returns position in the list, if no age in the list of dogs with age, method returns -1 public...

  • Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks...

    Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help. Specifications: The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods. A no- arg constructor that sets the monthNumber field to 1. A constructor that accepts the number of the month as an argument. It should...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

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