Advertisement
Guest User

Untitled

a guest
Nov 15th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. public class Song {
  2.  private String title;
  3. private String artist;
  4. private float duration;
  5. private float currentPlayPosition;
  6. private boolean isPlaying;
  7. private float fileSize;
  8.  
  9. public Song()
  10. {
  11.    
  12.     title = "NO TITLE";
  13.     artist = "NO ARTIST";
  14.     duration = 0.0f;
  15.     currentPlayPosition = 0.0f;
  16.     isPlaying = false;
  17.     fileSize = 0.0f;
  18.      System.out.println("Constructor is finished");
  19. }
  20.  
  21. public Song(String t, String a, float d)
  22. {
  23.      title = t;
  24.      artist = a;
  25.      duration = d;
  26.      currentPlayPosition = 0.0f;
  27.      isPlaying = false;
  28.      fileSize = 0.0f;
  29.      System.out.println("Constructor with parameters is finished");
  30. }
  31.  
  32. public String toString()
  33. {
  34.      return "'" + title + "' by " + artist + " lasts for "
  35.       + duration;
  36. }
  37.  
  38. public String getTitle()
  39. {
  40.    
  41.      return title;
  42. }
  43.  
  44. public String getArtist()
  45. {
  46.      return artist;
  47. }
  48.  
  49. public float getDuration()
  50. {
  51.      return duration;
  52. }
  53.  
  54. public boolean getIsPlaying()
  55. {
  56.      return isPlaying;
  57. }
  58.  
  59. public float getfileSize()
  60. {
  61.      return fileSize;
  62. }
  63.  
  64. public void setTitle(String newTitle)
  65. {
  66.     if (newTitle.compareTo("") != 0)
  67.     title = newTitle;
  68. }
  69.  
  70. public void setArtist(String newArtist)
  71. {
  72.     if (newArtist.compareTo("") != 0)
  73.     artist = newArtist;
  74. }
  75.  
  76. public void setDuration(float newDuration)
  77. {
  78.     if (newDuration >=0)
  79.     duration = newDuration;
  80. }
  81.  
  82. public void setfileSize(float newSize)
  83. {
  84.     if(newSize >=0)
  85.     fileSize = newSize;
  86. }
  87.  
  88. public void Play()
  89. {
  90.     isPlaying = true;
  91.     currentPlayPosition += 0.1f;
  92.     if (currentPlayPosition < duration)
  93.     {
  94.         System.out.println(title + " is playing at position "
  95.         + currentPlayPosition);
  96.     }
  97.     else
  98.     {
  99.         isPlaying = false;
  100.         System.out.println(title + " has finished playing.");
  101.         currentPlayPosition = 0.0f;
  102.     }
  103.    
  104.     }
  105.    
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement