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]";
}
}
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();
}
}
===========================================================================
Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...
This is my playlist class: class Playlist{ private String name; private int numberOfRecordings = 0; private int durationInSeconds = 0; private int MAX_PLAYLIST_SIZE; Recording recordingslist[]; Playlist(){ name = "Unknown"; MAX_PLAYLIST_SIZE = 5; recordingslist = new Recording[MAX_PLAYLIST_SIZE]; durationInSeconds = 0; } Playlist(String name, int size){ this.name = name; this.MAX_PLAYLIST_SIZE = size; recordingslist = new Recording[MAX_PLAYLIST_SIZE]; ...
Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java. Create two child classes named Cat.java and Dog.java. Cat.java should add attributes for color and breed. Dog.java should add attributes for breed and size (use String for small, medium, large). Add appropriate constructors, getter/setter methods and toString() methods. In a separate file named PetDriver.java, create a main. In the main, create an ArrayList of Pet. Add an instance of Cat and an instance of Dog to the ArrayList....
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 (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 -- 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...
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 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;
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 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: • 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...