From d30371fa2e848f98bffe9a7dde0959a1d49fb910 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 15:24:55 -0700 Subject: [PATCH 1/4] media class completed --- classes/Media.js | 16 ++++++++++++++++ main.js | 1 + package-lock.json | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/classes/Media.js b/classes/Media.js index d4d718b..06da96b 100644 --- a/classes/Media.js +++ b/classes/Media.js @@ -1,4 +1,20 @@ // create your Media class: +class Media { + + constructor(title, year, genre) { + this.title = title + this.year = year + this.genre = genre + Media.totalMediaCount++ + } + + summary() { + return (`Title: ${this.title}, Year: ${this.year}, Genre: ${this.genre}`) + } +} + +Media.totalMediaCount = 0 + // uncomment below to export it: module.exports = Media; diff --git a/main.js b/main.js index 102baa9..4f47cab 100644 --- a/main.js +++ b/main.js @@ -1 +1,2 @@ // Import classes here to console.log and debug +const Media = require('./classes/Media') \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 47c194a..55202d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4717,7 +4717,8 @@ "jest-pnp-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz", - "integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==" + "integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==", + "requires": {} }, "jest-regex-util": { "version": "29.4.3", From 80079b988cccae02914d5811b536f167d4800091 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 15:40:33 -0700 Subject: [PATCH 2/4] book class completed --- classes/Book.js | 29 ++++++++++++++++++++++++++++- main.js | 3 ++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/classes/Book.js b/classes/Book.js index ee69d54..b080424 100644 --- a/classes/Book.js +++ b/classes/Book.js @@ -1,6 +1,33 @@ // import the Media class: - +const Media = require('./Media') // create your Book class: +class Book extends Media { + constructor(title, year, genre, author, numPages, rating) { + super(title, year, genre) + this.author = author + this.numPages = numPages + this.rating = rating + } + + summary(){ + return (`Title: ${this.title}, Author: ${this.author}, Year: ${this.year}, Page Count: ${this.numPages}, Genre: ${this.genre}, Rating: ${this.rating}`) + } + + static highestRating(book) { + let highestRatedBook = book[0] + + for(let i = 0; i < book.length; i++) { + let rating = book[i].rating + + if (rating > highestRatedBook.rating) { + highestRatedBook = book[i] + } + } + + return highestRatedBook + } +} + // don't change below module.exports = Book; diff --git a/main.js b/main.js index 4f47cab..dc7bc16 100644 --- a/main.js +++ b/main.js @@ -1,2 +1,3 @@ // Import classes here to console.log and debug -const Media = require('./classes/Media') \ No newline at end of file +const Media = require('./classes/Media') +const Book = require('./classes/Book') \ No newline at end of file From 98708609cfc3070b1f050012a232957ca6c447b6 Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 15:47:55 -0700 Subject: [PATCH 3/4] movie class completed --- classes/Movie.js | 28 ++++++++++++++++++++++++++++ main.js | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/classes/Movie.js b/classes/Movie.js index 484e7a3..1abed03 100644 --- a/classes/Movie.js +++ b/classes/Movie.js @@ -1,6 +1,34 @@ // import the Media class: +const Media = require('./Media') // create your Movie class: +class Movie extends Media { + constructor(title, year, genre, director, duration, rating) { + super(title, year, genre) + this.director = director + this.duration = duration + this.rating = rating + } + + summary(){ + return (`Title: ${this.title}, Director: ${this.director}, Year: ${this.year}, Genre: ${this.genre}, Rating: ${this.rating}`) + } + + static longestMovie(movies) { + let longestMovieObject = movies[0] + + for(let i = 0; i < movies.length; i++) { + let duration = movies[i].duration + + if (duration > longestMovieObject.duration) { + longestMovieObject = movies[i] + } + } + + return longestMovieObject + } +} + // don't change below module.exports = Movie; \ No newline at end of file diff --git a/main.js b/main.js index dc7bc16..2a75b57 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,4 @@ // Import classes here to console.log and debug const Media = require('./classes/Media') -const Book = require('./classes/Book') \ No newline at end of file +const Book = require('./classes/Book') +const Movie = require('./classes/Movie') \ No newline at end of file From 721a59032d759f3b1d03ee72827ef9fbe903628d Mon Sep 17 00:00:00 2001 From: Mei Huang Date: Tue, 23 Apr 2024 15:55:00 -0700 Subject: [PATCH 4/4] music class completed --- classes/Music.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/classes/Music.js b/classes/Music.js index b97fe18..70be86a 100644 --- a/classes/Music.js +++ b/classes/Music.js @@ -1,6 +1,34 @@ // import the Media class: +const Media = require('./Media') // create your Music class: +class Music extends Media { + constructor(title, year, genre, artist, length) { + super(title, year, genre) + this.artist = artist + this.length = length + } + + summary(){ + return (`Title: ${this.title}, Artist: ${this.artist}, Year: ${this.year}, Genre: ${this.genre}, Length: ${this.length} seconds`) + } + + + static shortestAlbum(albums) { + let shortestAlbumObj = albums[0] + + for(let i = 0; i < albums.length; i++) { + let songLength = albums[i].length + + if (songLength < shortestAlbumObj.length) { + shortestAlbumObj = albums[i] + } + } + + return shortestAlbumObj + } +} + // don't change below module.exports = Music;