binibiningtinamoran

Album

Oct 29th, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.time.Duration;
  2. import java.util.ArrayList;
  3.  
  4. public class Album {
  5.  
  6.     private String name, band;
  7.     private Duration length; // total running time of the whole album
  8.  
  9.     public Album(String name, String band) {
  10.         this.name = name;
  11.         this.band = band;
  12.     }
  13.  
  14.     public String getName() {
  15.         return name;
  16.     }
  17.  
  18.     public void setName(String name) {
  19.         this.name = name;
  20.     }
  21.  
  22.     public String getBand() {
  23.         return band;
  24.     }
  25.  
  26.     public void setBand(String band) {
  27.         this.band = band;
  28.     }
  29.  
  30.     public Duration getLength() {
  31.         return length;
  32.     }
  33.  
  34.     public void addSong(Duration length) {
  35.         if (length == null) {
  36.             throw new IllegalArgumentException();
  37.         } else {
  38.             // Add the "length" paramter to the length of the album! Use +=
  39.         }
  40.     }
  41.  
  42.     public ArrayList <Duration> getSongs() {
  43.         return new ArrayList <Duration>(); // Change this!
  44.     }
  45.  
  46.     @Override
  47.     public boolean equals(Object obj) {
  48.         if (obj instanceof Album) {
  49.             Album that = (Album) obj;
  50.             return this.getName().equalsIgnoreCase(that.getName())
  51.                     && this.getBand().equalsIgnoreCase(that.getBand());
  52.         } else {
  53.             return false;
  54.         }
  55.     }
  56.  
  57.     @Override
  58.     public String toString() {
  59.         return "Album[" +
  60.                 "name= " + name + ", " +
  61.                 ", band= " + band + ", " +
  62.                 ", length= " + length + "]";
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment