Question

Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

Use inheritance to create a new class AudioRecording based on Recording class that:

  • it will retain all the members of the Recording class,

  • it will have an additional field bitrate (non-integer numerical; it cannot be modified once set),

  • its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors):

    • Non-parametrized constructor should set bitrate to zero,

    • If arguments for the parametrized constructor are illegal or null, it should behave as parametrized constructor

  • it will have an accessor / getter method for a new attribute field,

  • it will NOT have a mutator / setter method for a new attribute / field,

  • will override toString method

  • NOTE: Modify Recording class to facilitate inheritance as you go if necessary

Here is the recording class:

class Recording{

   private String ARTIST;
   private String NAME;
   private int DURATION_IN_SECONDS;
     
   Recording(){
       ARTIST = "Unknown";
       NAME = "Unknown";
       DURATION_IN_SECONDS = 0;
   }
     
   Recording(String ARTIST, String NAME, int DURATION_IN_SECONDS){
       if (ARTIST != null && NAME != null && DURATION_IN_SECONDS >0){
           this.ARTIST = ARTIST;
           this.NAME = NAME;
           this.DURATION_IN_SECONDS = DURATION_IN_SECONDS;
       } else {
           this.ARTIST = "Unknown";
           this.NAME = "Unknown";
           this.DURATION_IN_SECONDS = 0;
       }
   }

  
   public String getArtist(){
       return this.ARTIST;
   }
  
   public String getName(){
       return this.NAME;
   }
  
   public int getDuration(){
       return this.DURATION_IN_SECONDS;
   }
  
   public void play(){
       if (DURATION_IN_SECONDS > 0){
           int s = DURATION_IN_SECONDS % 60;
           int h = DURATION_IN_SECONDS / 60;
           int m = h % 60;
          
       System.out.println("Now Playing:"+ARTIST+"-" +NAME+ "[" +m+"m" +s+"s]");
      
       }
       else {
           System.out.println("ERROR: cannot play this recording");
       }
   }
  
   @Override
   public String toString(){
           int s = DURATION_IN_SECONDS % 60;
           int h = DURATION_IN_SECONDS / 60;
           int m = h % 60;
       return ARTIST +"-"+NAME +"[" +m+"m" +s+"s]";
}
  

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer.

Thanks!

===========================================================================


public class AudioRecording extends Recording {

    //additional field bitrate (non-integer numerical;
    private final double bitrate;

    //its constructors (non-parametrized)
    public AudioRecording() {
        super();
        //Non-parametrized constructor should set bitrate to zero,
        bitrate=0.0;
    }
    //its constructors (parametrized)
    public AudioRecording(double bitrate) {
        this.bitrate = bitrate;
    }

    //its constructors (parametrized)
    public AudioRecording(String ARTIST, String NAME, int DURATION_IN_SECONDS, double bitrate) {
        super(ARTIST, NAME, DURATION_IN_SECONDS);
        this.bitrate = bitrate;
    }

    //it will have an accessor / getter method for a new attribute field,
    public double getBitrate() {
        return bitrate;
    }

    //will override toString method

    @Override
    public String toString() {
        return super.toString()+" BitRate: "+getBitrate();
    }
}


===========================================================================

Add a comment
Know the answer?
Add Answer to:
Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...
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
  • java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the...

    java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date {    private String month;    private String day;    private String year;    public Date(String month, String day, String year) {       this.month = month;       this.day = day;       this.year = year;    }    public String getMonth() {       return month;    }    public String getDay() {       return day;    }    public String...

  • using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship...

    using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship (all attributes private) String attribute for the name of ship float attribute for the maximum speed the of ship int attribute for the year the ship was built Add the following behaviors constructor(default and parameterized) , finalizer, and appropriate accessor and mutator methods Override the toString() method to output in the following format if the attributes were name="Sailboat Sally", speed=35.0f and year built of...

  • Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player --...

    Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player -- sorting song lists. In this assignment, you are asked to design a graphic user interface (GUI) for this function. To start, create a Java project named CS235A4_YourName. Then, copy the class Singer and class Song from finished Lab 4 and paste into the created project (src folder). Define another class TestSongGUI to implement a GUI application of sorting songs. Your application must provide the...

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • I need help with my code. It keeps getting this error: The assignment is: Create a...

    I need help with my code. It keeps getting this error: The assignment is: Create a class to represent a Food object. Use the description provided below in UML. Food name : String calories : int Food(String, int) // The only constructor. Food name and calories must be // specified setName(String) : void // Sets the name of the Food getName() : String // Returns the name of the Food setCalories(int) : void // Sets the calories of the Food...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • In java 8. Modify the averageTopSpeed() method (in the class FormulaOne) using only lambdas and streams...

    In java 8. Modify the averageTopSpeed() method (in the class FormulaOne) using only lambdas and streams and print it to the terminal via the driver class: import java.util.*; public class Racer implements Comparable { private final String name; private final int year; private final int topSpeed;    public Racer(String name, int year, int topSpeed){    this.name = name; this.year = year; this.topSpeed = topSpeed;    }    public String toString(){    return name + "-" + year + ", Top...

  • QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members:...

    QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...

  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...

    Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...

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