atanasovetr

Music

Jan 27th, 2021
711
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. class Musician {
  6.     protected String name;
  7.     protected String number;
  8.     protected String address;
  9.  
  10.     public Musician(String name, String number, String address) {
  11.         this.name = name;
  12.         this.number = number;
  13.         this.address = address;
  14.     }
  15.  
  16.     public String getName() {
  17.         return name;
  18.     }
  19.  
  20.     public void setName(String name) {
  21.         this.name = name;
  22.     }
  23.  
  24.     public String getNumber() {
  25.         return number;
  26.     }
  27.  
  28.     public void setNumber(String number) {
  29.         this.number = number;
  30.     }
  31.  
  32.     public String getAddress() {
  33.         return address;
  34.     }
  35.  
  36.     public void setAddress(String address) {
  37.         this.address = address;
  38.     }
  39. }
  40.  
  41.  
  42. class Group{
  43.     protected Musician[] group = new Musician[10];
  44.  
  45.     public Group(){
  46.  
  47.     }
  48.  
  49.     public Group(Musician[] group) {
  50.         this.group = group;
  51.     }
  52.  
  53.     public Musician[] getGroup() {
  54.         return group;
  55.     }
  56.  
  57.     public void setGroup(Musician[] group) {
  58.         this.group = group;
  59.     }
  60. }
  61.  
  62. abstract class AudioDevice{
  63.     protected Group group;
  64.     protected String albumName;
  65.  
  66.     public abstract String[] getTracks();
  67.     public abstract double getLength();
  68.  
  69.     @Override
  70.     public String toString() {
  71.         return  "Group: " + group +
  72.                 ", Album name: '" + albumName;
  73.     }
  74.  
  75.     public Group getGroup() {
  76.         return group;
  77.     }
  78.  
  79.     public void setGroup(Group group) {
  80.         this.group = group;
  81.     }
  82.  
  83.     public String getAlbumName() {
  84.         return albumName;
  85.     }
  86.  
  87.     public void setAlbumName(String albumName) {
  88.         this.albumName = albumName;
  89.     }
  90. }
  91.  
  92. class Song{
  93.     protected int number;
  94.     protected double songLength;
  95.     protected String name;
  96.  
  97.     public Song(int number, double songLength, String name) {
  98.         this.number = number;
  99.         this.songLength = songLength;
  100.         this.name = name;
  101.     }
  102.  
  103.  
  104.     public int getNumber() {
  105.         return number;
  106.     }
  107.  
  108.     public void setNumber(int number) {
  109.         this.number = number;
  110.     }
  111.  
  112.     public double getSongLength() {
  113.         return songLength;
  114.     }
  115.  
  116.     public void setSongLength(double songLength) {
  117.         this.songLength = songLength;
  118.     }
  119.  
  120.     public String getName() {
  121.         return name;
  122.     }
  123.  
  124.     public void setName(String name) {
  125.         this.name = name;
  126.     }
  127.  
  128.     @Override
  129.     public String toString() {
  130.         return  "Number: " + number +
  131.                 ", Length of the song: " + songLength +
  132.                 ", Name of the song: '" + name + '\n';
  133.     }
  134. }
  135.  
  136. class CD extends AudioDevice{
  137.     protected Song[] songs = new Song[30];
  138.  
  139.     public CD(){
  140.  
  141.     }
  142.  
  143.     public CD(Song[] songs) {
  144.         this.songs = songs;
  145.     }
  146.  
  147.     public String[] getTracks(){
  148.         String[] songNames = new String[30];
  149.         for(int i = 0; i < 30; i++) {
  150.             songNames[i] = songs[i].getName();
  151.         }
  152.         return songNames;
  153.     }
  154.     public double getLength(){
  155.         double totalLength = 0;
  156.         for (Song song: songs){
  157.             totalLength += song.getSongLength();
  158.         }
  159.         return totalLength;
  160.     }
  161.  
  162.     public Song[] getSongs() {
  163.         return songs;
  164.     }
  165.  
  166.     public void setSongs(Song[] songs) {
  167.         this.songs = songs;
  168.     }
  169.  
  170.     @Override
  171.     public String toString() {
  172.         StringBuilder str = new StringBuilder();
  173.         for(Song song: this.songs){
  174.             str.append(song.toString());
  175.         }
  176.         return  super.toString() + str;
  177.     }
  178. }
  179.  
  180. class Store{
  181.     ArrayList<CD> albums = new ArrayList<>();
  182.  
  183.     public Store(){
  184.  
  185.     }
  186.  
  187.     public Store(ArrayList<CD> albums) {
  188.         this.albums = albums;
  189.     }
  190.  
  191.     public void addAlbum(CD albumToAdd){
  192.         this.albums.add(albumToAdd);
  193.     }
  194.  
  195.     public void printByMusician(Musician musicianToSearch){
  196.         for(CD album: this.albums){
  197.             for (Musician musician: album.getGroup().getGroup()){
  198.                 if(musician.equals(musicianToSearch)){
  199.                     System.out.println(album);
  200.                 }
  201.             }
  202.  
  203.         }
  204.     }
  205.    
  206. }
RAW Paste Data