Lab 6, documentation.
This commit is contained in:
parent
d5cd53f954
commit
aadc3f5d05
|
@ -2,17 +2,31 @@ package OOP.Java.lab_6
|
|||
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
* Represents an album by a specific artist, containing multiple tracks.
|
||||
*
|
||||
* @property albumName The name of the album.
|
||||
* @property artist The artist or band associated with the album.
|
||||
* @property tracks An [Array] of tracks included on the album.
|
||||
*/
|
||||
class Album(val albumName: String, val artist: String, val tracks: Array<Track>) {
|
||||
|
||||
/**
|
||||
* Returns an array of tracks within the specified duration range.
|
||||
*/
|
||||
fun tracksInDurationRange(durationRange: ClosedRange<Duration>): Array<Track> {
|
||||
return this.tracks.filter { it.duration in durationRange }.toTypedArray()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total duration of all tracks on the album.
|
||||
*/
|
||||
fun totalDuration(): Duration {
|
||||
var totalDuration: Duration = Duration.ZERO
|
||||
this.tracks.forEach { totalDuration += it.duration }
|
||||
return totalDuration
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "${this.albumName} by ${this.artist}\nTotal duration: ${this.totalDuration()}\nTracks:\n${this.tracks.joinToString("\n")}"
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package OOP.Java.lab_6
|
||||
|
||||
import kotlin.time.Duration
|
||||
|
||||
class DancePop(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Dance-pop"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package OOP.Java.lab_6
|
||||
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
* Represents a track in the Dance-pop style.
|
||||
*
|
||||
* @param numberInAlbum The position of the track on the album.
|
||||
* @param trackName The name of the track.
|
||||
* @param feature The featured artist(s) in the track (nullable if no featured artist).
|
||||
* @param duration The [Duration] of the track.
|
||||
*/
|
||||
class Dancepop(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Dance-pop"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package OOP.Java.lab_6
|
||||
|
||||
import kotlin.time.Duration
|
||||
|
||||
class ElectroPop(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Electropop"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package OOP.Java.lab_6
|
||||
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
* Represents a track in the Electropop style.
|
||||
*
|
||||
* @param numberInAlbum The position of the track on the album.
|
||||
* @param trackName The name of the track.
|
||||
* @param feature The featured artist(s) in the track (nullable if no featured artist).
|
||||
* @param duration The [Duration] of the track.
|
||||
*/
|
||||
class Electropop(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Electropop"
|
||||
}
|
|
@ -2,6 +2,14 @@ package OOP.Java.lab_6
|
|||
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
* Represents an interlude track.
|
||||
*
|
||||
* @param numberInAlbum The position of the track on the album.
|
||||
* @param trackName The name of the track.
|
||||
* @param feature The featured artist(s) in the track (nullable if no featured artist).
|
||||
* @param duration The [Duration] of the track.
|
||||
*/
|
||||
class Interlude(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Interlude"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package OOP.Java.lab_6
|
||||
|
||||
import kotlin.time.Duration
|
||||
|
||||
class SynthPop(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Synth-pop"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package OOP.Java.lab_6
|
||||
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
* Represents a track in the Synth-pop style.
|
||||
*
|
||||
* @param numberInAlbum The position of the track on the album.
|
||||
* @param trackName The name of the track.
|
||||
* @param feature The featured artist(s) in the track (nullable if no featured artist).
|
||||
* @param duration The [Duration] of the track.
|
||||
*/
|
||||
class Synthpop(numberInAlbum: Int, trackName: String, feature: String?, duration: Duration): Track(numberInAlbum, trackName, feature, duration) {
|
||||
override val style = "Synth-pop"
|
||||
}
|
|
@ -2,9 +2,21 @@ package OOP.Java.lab_6
|
|||
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
* Represents a track on an album.
|
||||
*
|
||||
* @param numberInAlbum The position of the track on the album.
|
||||
* @param trackName The name of the track.
|
||||
* @param feature The featured artist(s) in the track (nullable if no featured artist).
|
||||
* @param duration The [Duration] of the track.
|
||||
*/
|
||||
open class Track(val numberInAlbum: Int, val trackName: String, val feature: String?, val duration: Duration) {
|
||||
|
||||
/**
|
||||
* The style or genre of the track.
|
||||
*/
|
||||
open val style = ""
|
||||
|
||||
override fun toString(): String {
|
||||
return if (this.feature == null) {
|
||||
"#${this.numberInAlbum}: ${this.trackName} (${this.duration})"
|
||||
|
|
|
@ -4,26 +4,27 @@ import kotlin.time.Duration.Companion.minutes
|
|||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
fun main() {
|
||||
|
||||
val chromatica = Album(
|
||||
"Chromatica",
|
||||
"Lady Gaga",
|
||||
arrayOf(
|
||||
Interlude(1, "Chromatica I", null, 1.minutes),
|
||||
SynthPop(2, "Alice", null, 2.minutes + 57.seconds),
|
||||
DancePop(3, "Stupid Love", null, 3.minutes + 13.seconds),
|
||||
DancePop(4, "Rain On Me", "Ariana Grande", 3.minutes + 2.seconds),
|
||||
SynthPop(5, "Free Woman", null, 3.minutes + 11.seconds),
|
||||
ElectroPop(6, "Fun Tonight", null, 2.minutes + 53.seconds),
|
||||
Synthpop(2, "Alice", null, 2.minutes + 57.seconds),
|
||||
Dancepop(3, "Stupid Love", null, 3.minutes + 13.seconds),
|
||||
Dancepop(4, "Rain On Me", "Ariana Grande", 3.minutes + 2.seconds),
|
||||
Synthpop(5, "Free Woman", null, 3.minutes + 11.seconds),
|
||||
Electropop(6, "Fun Tonight", null, 2.minutes + 53.seconds),
|
||||
Interlude(7, "Chromatica II", null, 41.seconds),
|
||||
SynthPop(8, "911", null, 2.minutes + 52.seconds),
|
||||
ElectroPop(9, "Plastic Doll", null, 3.minutes + 41.seconds),
|
||||
DancePop(10, "Sour Candy", "Blackpink", 2.minutes + 37.seconds),
|
||||
DancePop(11, "Enigma", null, 2.minutes + 59.seconds),
|
||||
SynthPop(12, "Replay", null, 3.minutes + 6.seconds),
|
||||
Synthpop(8, "911", null, 2.minutes + 52.seconds),
|
||||
Electropop(9, "Plastic Doll", null, 3.minutes + 41.seconds),
|
||||
Dancepop(10, "Sour Candy", "Blackpink", 2.minutes + 37.seconds),
|
||||
Dancepop(11, "Enigma", null, 2.minutes + 59.seconds),
|
||||
Synthpop(12, "Replay", null, 3.minutes + 6.seconds),
|
||||
Interlude(13, "Chromatica III", null, 27.seconds),
|
||||
ElectroPop(14, "Sine From Above", "Elton John", 4.minutes + 4.seconds),
|
||||
SynthPop(15, "1000 Doves", null, 3.minutes + 35.seconds),
|
||||
DancePop(16, "Babylon", null, 2.minutes + 41.seconds)
|
||||
Electropop(14, "Sine From Above", "Elton John", 4.minutes + 4.seconds),
|
||||
Synthpop(15, "1000 Doves", null, 3.minutes + 35.seconds),
|
||||
Dancepop(16, "Babylon", null, 2.minutes + 41.seconds)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue