Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Song {
- private String title;
- private String artist;
- private float duration;
- private float currentPlayPosition;
- private boolean isPlaying;
- private float fileSize;
- public Song()
- {
- title = "NO TITLE";
- artist = "NO ARTIST";
- duration = 0.0f;
- currentPlayPosition = 0.0f;
- isPlaying = false;
- fileSize = 0.0f;
- System.out.println("Constructor is finished");
- }
- public Song(String t, String a, float d)
- {
- title = t;
- artist = a;
- duration = d;
- currentPlayPosition = 0.0f;
- isPlaying = false;
- fileSize = 0.0f;
- System.out.println("Constructor with parameters is finished");
- }
- public String toString()
- {
- return "'" + title + "' by " + artist + " lasts for "
- + duration;
- }
- public String getTitle()
- {
- return title;
- }
- public String getArtist()
- {
- return artist;
- }
- public float getDuration()
- {
- return duration;
- }
- public boolean getIsPlaying()
- {
- return isPlaying;
- }
- public float getfileSize()
- {
- return fileSize;
- }
- public void setTitle(String newTitle)
- {
- if (newTitle.compareTo("") != 0)
- title = newTitle;
- }
- public void setArtist(String newArtist)
- {
- if (newArtist.compareTo("") != 0)
- artist = newArtist;
- }
- public void setDuration(float newDuration)
- {
- if (newDuration >=0)
- duration = newDuration;
- }
- public void setfileSize(float newSize)
- {
- if(newSize >=0)
- fileSize = newSize;
- }
- public void Play()
- {
- isPlaying = true;
- currentPlayPosition += 0.1f;
- if (currentPlayPosition < duration)
- {
- System.out.println(title + " is playing at position "
- + currentPlayPosition);
- }
- else
- {
- isPlaying = false;
- System.out.println(title + " has finished playing.");
- currentPlayPosition = 0.0f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement