import java.util.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.lang.String;
/**
* Define a Java class to store information about music tracks.
*
* @author (JIAMING LI)
* @version (25/10/2011)
*/
public class Track
{
// instance variables - define the information that need to stored in the track
private String title;
private Artist artist;
private Date date;
private int length;
private int rating;
private int size;
private int playCount;
private String location;
private ArrayList<Artist> guestArtist;
/**
* Constructor for objects of class Tracks
*/
public Track(String title, Artist artist, int rating)
{
this();
this.title = title;
this.artist = artist;
if(rating >=0 && rating <=5)
{
this.rating = rating;
}
else
{
System.out.println("You enter the invaild number,try again");
}
}
public Track(String title, Artist artist, int rating, int length, int size)
{
this(title, artist, rating);
this.length = length;
this.size = size;
}
public Track()
{
// initialise instance variables
length = 0;
rating = 1;
size = 0;
location = "UK";
date = new Date();
guestArtist = new ArrayList<Artist>();
}
/**
* method - o set and get the title, artist, date, length, rating, location and sized of the track
*/
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public Artist getArtist()
{
return artist;
}
public void setArtist(Artist artist)
{
this.artist = artist;
}
public Date getDate()
{
return date;
}
public void setDate(String s)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try
{
this.date = sdf.parse(s);
}
catch(ParseException e)
{
e.printStackTrace();
}
}
public int getLength()
{
return length;
}
public void setLength(int length)
{
this.length = length;
}
public void setRating(int rating)
{
// put your code here
if(rating >=0 && rating <=5)
{
this.rating = rating;
}
else
{
System.out.println("You enter the invaild number,try again");
}
}
public int getRating()
{
return rating;
}
public void setSize(int size)
{
this.size = size;
}
public int getSize()
{
return size;
}
public void setLocation(String location)
{
this.location = location;
}
public String getLocation()
{
return location;
}
/**
* add a guest artist to the track
*/
public void addGuestArtist(Artist guest)
{
guestArtist.add(guest);
}
public ArrayList<Artist> getGuestArtist()
{
return guestArtist;
}
/**
* get a list of all individuals on the track, including band members and guset artists.
*/
public ArrayList<Artist> getAllMembers()
{
ArrayList<Artist> allMembers = new ArrayList<Artist>();
allMembers = artist.getMembers();
if(guestArtist !=null)
{
allMembers.addAll(guestArtist);
}
return allMembers;
}
/**
* add to the play count of a track
*/
public void play()
{
playCount++;
}
/**
* get the play count of a track
*/
public int getPlayCount()
{
return playCount;
}
public String toString()
{
return "Track Title: " + title + ". \n" +
"Artist: " + artist.getName() + ".\n" +
"Length: " + length + ". \n" +
"Date" + SimpleDateFormat.getDateInstance().format(date) + ". \n" +
"Size " + size + ". \n" +
"Location " + location + ". \n" +
"Rating " + rating + ". \n" ;
}
static String artistName;
public String toString2()
{
return "Track Title: " + title + ".\n" +
artistName + ".\n" +
"Date: " + DateFormat.getDateInstance().format(date) + ".\n" +
"Length: " + length + ".\n" +
"Rating: " + rating + ".\n" +
"Location: " + location + ".\n" +
"Size: " + size + ".\n";
}
public static Track forUserEnter()
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the information of a Track");
Track track = new Track();
System.out.println("Title: ");
String title = sc.next();
track.setTitle(title);
System.out.println("Artist(Please enter the file name of artist)");
String artise = sc.next();
System.out.println("Date(yyyy-MM-dd): ");
String date = sc.next();
track.setDate(date);
System.out.println("Rating: ");
int rating = sc.nextInt();
track.setRating(rating);
System.out.println("Length: ");
int length = sc.nextInt();
track.setLength(length);
System.out.println("Size: ");
int size = sc.nextInt();
track.setSize(size);
System.out.println("Location: ");
String location = sc.next();
track.setLocation(location);
return track;
}
public static void main(String[] args)
{
Band bs = new Band("Back Street");
bs.addMembers(new Artist("12345"));
bs.addMembers(new Artist("56789"));
bs.addMembers(new Artist("23213"));
bs.addMembers(new Artist("31313"));
Track track = new Track("Season in the sun", bs, 5);
track.addGuestArtist(new Artist("23132"));
ArrayList<Artist> allMembers = track.getAllMembers();
System.out.println("All the individuals on the track ");
for(Artist tem : allMembers)
{
System.out.println(tem.getName());
}
track.play();
track.play();
System.out.println("THis song has been played for " + track);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA音乐库完整代码
共17个文件
java:7个
class:7个
classpath:1个
4星 · 超过85%的资源 需积分: 10 14 下载量 32 浏览量
2012-01-09
06:28:51
上传
评论 2
收藏 21KB ZIP 举报
温馨提示
这是一个完整的音乐库的代码,用户可以自己运行,创建音乐集,专辑,输入歌手名,歌曲名等等
资源推荐
资源详情
资源评论
收起资源包目录
Music Library2.zip (17个子文件)
Music Library2
bin
Library.class 3KB
Artist.class 2KB
Album.class 6KB
Band.class 2KB
Track.class 6KB
Series.class 571B
ForUser.class 3KB
.settings
org.eclipse.jdt.core.prefs 629B
src
ForUser.java 2KB
Album.java 4KB
Library.java 2KB
Series.java 325B
Band.java 1KB
Track.java 6KB
Artist.java 2KB
.project 389B
.classpath 301B
共 17 条
- 1
资源评论
- 碎冰点2013-01-13代码倒是挺不错,就是有点浅。
lokben
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功