You're building a virtual library app, and you need to create a set of classes to represent different types of media. You'll have books, movies, and music, each with their own unique properties. You'll need to create a base class for all media, and several subclasses for specific types of media. You'll also need to create a static method to keep track of the total number of media items in the library.
- You can run any of the files with the command
node PATH_TO_FILE
. - To run the tests, do the following in the root folder of this project:
npm install
npm test
Underlined items are static method. Italicized items are static properties
- In
Media.js
, create aMedia
class. TheMedia
class should have the following properties and methods:title
: the title of the media (string)year
: the year the media was produced (number)genre
: the genre of the media (string)totalMediaCount
: A static property that tracks how many Media items have been createdsummary()
: a method that returns a summary of the media (string) as"Title: <TITTLE>, Year: <YEAR>, Genre: <GENRE>"
- Export the
Media
class usingmodule.exports
. - In
index.js
, importMedia
usingrequire
.
const book = new Media('The Catcher in the Rye', 1951, 'Fiction');
Media.totalMediaCount; // 1
const music = new Media('Abbey Road', 1969, 'Rock');
Media.totalMediaCount; // 2
music.summary(); // "Title: Abbey Road, Year: 1969, Genre: Rock"
- In
Book.js
, create aBook
class. TheBook
class should be a subclass ofMedia
. ImportMedia
into theBook.js
file usingrequire
. Book
should have the following properties and methods:author
: the author of the book (string)numPages
: the number of pages in the book (number)rating
: the average rating of the book (number between 1-5)summary()
: a method that returns a summary of the book, including the author, number of pages, and rating (string) as"Title: <TITTLE>, Author: <AUTHOR>, Year: <YEAR>, Page Count: <NUM_PAGES>, Genre: <GENRE>, Rating: <RATING>"
- The
Book
class should have a static methodhighestRating
that takes an array ofBook
items and returns theBook
with the highest rating. - Export the
Book
class usingmodule.exports
. - In
index.js
, importBook
usingrequire
.
const book1 = new Book('To Kill a Mockingbird', 1960, 'Fiction', 'Harper Lee', 281, 4.4);
Media.totalMediaCount; // 1
const book2 = new Book('The Bluest Eye', 1970, 'Fiction', 'Toni Morrison', 206, 4.6);
Media.totalMediaCount; // 2
book1.summary(); // "Title: To Kill a Mockingbird, Author: Harper Lee, Year: 1960, Page Count: 281, Genre: Fiction, Rating: 4.4"
Book.highestRating([book1, book2]); // Returns book2
- In
Movie.js
, create aMovie
class. TheMovie
class should be a subclass ofMedia
. ImportMedia
into theMovie.js
file usingrequire
. Music
should have the following properties and methods:director
: the director of the movie (string)duration
: the duration of the movie in minutes (number)rating
: the average rating of the movie (number between 1-5)summary()
: a method that returns a summary of the movie, including the director, duration, and rating (string) as"Title: <TITTLE>, Director: <DIRECTOR>, Year: <YEAR>, Genre: <GENRE>, Duration: <DURATION>, Rating: <RATING>"
- The
Movie
class should have a static methodlongestMovie
that takes an array ofMovie
objects and returns theMovie
with the longest duration. - Export the
Movie
class usingmodule.exports
. - In
index.js
, importMovie
usingrequire
.
const movie1 = new Movie('Inception', 2010, 'Sci-Fi', 'Christopher Nolan', 148, 4.5);
const movie2 = new Movie('The Godfather', 1972, 'Crime', 'Francis Ford Coppola', 175, 4.7);
Media.totalMediaCount; // 2
movie1.summary(); // "Title: Inception, Director: Christopher Nolan, Year: 2010, Genre: Sci-Fi, Rating: 4.5"
Movie.longestMovie([movie1, movie2]); // Returns movie2
- In
Music.js
, create aMusic
class. TheMusic
class should be a subclass ofMedia
. ImportMedia
into theMusic.js
file usingrequire
. Music
should have the following properties and methods:artist
: the artist of the music (string)length
: the length of the music in seconds (number)summary()
: a method that returns a summary of the music, including the artist, album, and length (string) as"Title: <TITTLE>, Artist: <ARTIST>, Year: <YEAR>, Genre: <GENRE>, Length: <LENGTH>"
- The
Music
class should have a static methodshortestAlbum
that takes an array ofMusic
objects and returns theMusic
object with the shortest song length. - Export the
Music
class usingmodule.exports
. - In
index.js
, importMusic
usingrequire
.
const music1 = new Music('Lemonade', 2016, 'R&B', 'Beyonce', 'Lemonade', 3949);
const music2 = new Music('Renaissance', 2022, 'R&B', 'Beyonce', 'Beyonce', 3734);
Media.totalMediaCount; // 2
music2.summary(); // "Title: Renaissance, Artist: Beyonce, Year: 2022, Genre: R&B, Length: 3734 seconds"
Music.shortestAlbum([music1, music2]); // Returns music2
- Create a class of
Podcast
that is a subclass ofMusic
.Podcast
should inherit all of the properties and methods from theMusic
class and have an additional properties and methods of:host
: A string with the name of the host.episodeName
: A string with the name of the episodeepisodeNumber
: A number with the episode number.guests
: An array of the guests on the particular episode.listen()
: Methods that returns the string<TITLE> - Episode: <EPISODE_TITLE>. Hosted by <HOST> and featuring guests <GUESTS>. Length: <LENGTH> seconds.
- Add a static method to
Book
andMovie
calledcalculateAverageRating()
: This should accept an array ofBook
orMovie
objects and return the average rating for these objects. - In
Media
create a static property ofALL_MEDIA
. This should be an array that contains allMedia
objects created using the class.