Created
September 11, 2018 18:39
-
-
Save EnioRich/ab04fa8a72695845189b63c217596813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Lesson_3_4.Lesson_3_Task_1; | |
public class AudioContent { | |
private byte [] content; | |
public AudioContent (byte[]content){ | |
this.content = content; | |
} | |
public byte[] getContent(){ | |
return content; | |
} | |
@Override | |
public String toString() { | |
return "AudioContent{" + | |
"content=" + content + | |
'}'; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Lesson_3_4.Lesson_3_Task_1; | |
public class MusicRunner { | |
public static void main(String[] args) { | |
Song firtsong = new Song("The Madness", "Alevela", "Pop Punk", 3, | |
new AudioContent(new byte[]{1})); | |
Song secondsong = new Song("The Criminal", "Unions", "Rock", 4, | |
new AudioContent(new byte[]{2})); | |
Song thirdsong = new Song("Man", "Sam Tinnesz", "Pop", 3, | |
new AudioContent(new byte[]{3})); | |
Song fourthsong = new Song("You can run", "Adam Jones", "Rock", 4, | |
new AudioContent(new byte[]{4})); | |
Song fifthsong = new Song("Changes", "Souls harbor", "Easy listening", 3, | |
new AudioContent(new byte[]{5})); | |
Song sixthsong = new Song("Get Up", "Shim", "Pop Punk", 5, | |
new AudioContent(new byte[]{6})); | |
String a = firtsong.getTitle(); | |
long b = fifthsong.getLength(); | |
String c = firtsong.getGenre(); | |
System.out.println(a); // The Madness | |
System.out.println(b); // 3 | |
System.out.println(c); // Pop Punk | |
Playlist playlist1 = new Playlist("run"); | |
Playlist playlist2 = new Playlist("walk"); | |
playlist1.addsong(firtsong); | |
playlist1.addsong(secondsong); | |
playlist1.addsong(thirdsong); | |
playlist2.addsong(fourthsong); | |
playlist2.addsong(fifthsong); | |
playlist2.addsong(sixthsong); | |
String z = playlist1.getTitle(); | |
System.out.println(z); // run | |
long x = playlist2.getTotalLength(); | |
System.out.println(x); // 12 | |
System.out.println(playlist1.findByTitlePart("The Criminal")); | |
// [Song{title='The Criminal', author='Unions', genre='Rock', length=4, | |
// content=AudioContent{content=[B@3b81a1bc}}] | |
System.out.println(playlist1.findByAuthor("Alevela")); | |
// [Song{title='The Madness', author='Alevela', genre='Pop Punk', length=3, | |
// content=AudioContent{content=[B@64616ca2}}] | |
User black = new User("white"); | |
black.addSongToPlaylist("run", sixthsong); | |
System.out.println(playlist2.findByAuthor("Shim")); // [Song{title='Get Up', author='Shim', genre='Pop Punk', | |
// length=5, content=AudioContent{content=[B@4e04a765}}] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Lesson_3_4.Lesson_3_Task_1; | |
import java.lang.reflect.Array; | |
import java.util.ArrayList; | |
public class Playlist { | |
private String title; | |
private ArrayList <Song> songs = new ArrayList<>(); | |
public Playlist(String title){ | |
this.title = title; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void addsong (Song song){ | |
songs.add(song); | |
} | |
public long getTotalLength(){ | |
long length = 0; | |
for (Song song : songs){ | |
length = (length + song.getLength()); | |
} | |
return length; | |
} | |
public ArrayList <Song> findByTitlePart (String title){ | |
ArrayList <Song> searchingsong = new ArrayList<>(); | |
for (Song song : songs){ | |
if (song.getTitle() == title){ | |
searchingsong.add(song); | |
} | |
} | |
return searchingsong; | |
} | |
public ArrayList <Song> findByAuthor (String author){ | |
ArrayList <Song> searchingsong = new ArrayList<>(); | |
for (Song song : songs){ | |
if (song.getAuthor() == author){ | |
searchingsong.add(song); | |
} | |
} | |
return searchingsong; | |
} | |
@Override | |
public String toString() { | |
return "Playlist{" + | |
"title='" + title + '\'' + | |
", songs=" + songs + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Lesson_3_4.Lesson_3_Task_1; | |
public class Song { | |
private String title; | |
private String author; | |
private String genre; | |
private int length; | |
private AudioContent content; | |
public Song (String title, String author, String genre, int length, AudioContent content) { | |
this.title = title; | |
this.author = author; | |
this.genre = genre; | |
this.length = length; | |
this.content = content; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public String getAuthor() { | |
return author; | |
} | |
public String getGenre() { | |
return genre; | |
} | |
public int getLength () { | |
return length; | |
} | |
public AudioContent getContent () { | |
return content; | |
} | |
@Override | |
public String toString() { | |
return "Song{" + | |
"title='" + title + '\'' + | |
", author='" + author + '\'' + | |
", genre='" + genre + '\'' + | |
", length=" + length + | |
", content=" + content + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Lesson_3_4.Lesson_3_Task_1; | |
import java.util.ArrayList; | |
public class User { | |
private String name; | |
private ArrayList<Playlist> playlists = new ArrayList<>(); | |
public User(String name) { | |
this.name = name; | |
} | |
public String getName (){ | |
return name; | |
} | |
public Playlist createPlaylist (String newPlaylist){ | |
Playlist playlist = new Playlist(newPlaylist); | |
playlists.add(playlist); | |
return playlist; | |
} | |
public Playlist findByTitle (String title){ | |
Playlist searchplaylist = new Playlist(title); | |
for (Playlist playlist : playlists ){ | |
if (title == playlist.getTitle()){ | |
searchplaylist = playlist; | |
} | |
} | |
return searchplaylist; | |
} | |
public void addSongToPlaylist (String playlisttitle, Song song){ | |
for (Playlist playlist : playlists){ | |
if (playlist.getTitle() == playlisttitle){ | |
playlist.addsong(song); | |
} | |
} | |
} | |
@Override | |
public String toString() { | |
return "User{" + | |
"name='" + name + '\'' + | |
", playlists=" + playlists + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment