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

Below is the outline for a Media class. The outline already defines two fields a

ID: 3770533 • Letter: B

Question

Below is the outline for a Media class. The outline already defines two fields and a constructor to initialize the fields.

Add one accessor method and one mutator method to the class – getAuthor and changeTitle – that return the author and change title fields as their respective results. Test your class by creating some instances and calling the methods.

/**

* A class that maintains information on a media.

* This might form part of a larger application such

* as a library system, for instance.

*

* @author (Insert your name here.)

* @version (Insert today's date here.)

*/

class Media

{

    // The fields.

    private String author;

    private String title;

    /**

     * Set the author and title fields when this object

     * is constructed.

     */

    public Media(String mediaAuthor, String mediaTitle)

    {

        author = mediaAuthor;

        title = mediaTitle;

    }

    // Add your methods here.

}

Explanation / Answer

/**
* A class that maintains information on a media. This might form part of a
* larger application such as a library system, for instance.
*
* @author (Insert your name here.)
* @version (Insert today's date here.)
*/
class Media {
   // The fields.
   private String author;
   private String title;

   /**
   * Set the author and title fields when this object is constructed.
   */
   public Media(String mediaAuthor, String mediaTitle) {
       author = mediaAuthor;
       title = mediaTitle;
   }

   /**
   * @return the author
   */
   public String getAuthor() {
       return author;
   }

   /**
   * @param author
   * the author to set
   */
   public void setAuthor(String author) {
       this.author = author;
   }

   /**
   * @return the title
   */
   public String getTitle() {
       return title;
   }

   /**
   * @param title
   * the title to set
   */
   public void setTitle(String title) {
       this.title = title;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Media [author=" + author + ", title=" + title + "]";
   }

   // Add your methods here.

   /**
   * @param args
   */
   public static void main(String[] args) {

       Media media1 = new Media("author1", "title1");
       System.out.println("media1-->" + media1.toString());
       media1.setAuthor("new author1");
       media1.setTitle("new title1");

       System.out.println("media1-->" + media1.toString());

   }
}

OUTPUT:

media1-->Media [author=author1, title=title1]
media1-->Media [author=new author1, title=new title1]

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