Java初学者寻求帮助(创建一个简单的MP3播放器 [英] Java beginner looking for help (create a simple MP3 player

查看:63
本文介绍了Java初学者寻求帮助(创建一个简单的MP3播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大学作业要完成,我已经编写了一些代码,但是它不是很好并且不能正常工作,我想知道是否有一个示例代码可以使用/关注以使我对如何获得代码有所了解.作业开始了.

作业问题:

编写一个程序,该程序将实现简单MP3播放器的某些功能.您应该开发一个程序,使我们可以添加,删除,分类和搜索音乐曲目的集合.每个曲目均以艺术家,歌曲名称,发行年份,时间和大小(以MB为单位)为特征.创建对象时,应初始化所有属性.

您的类应重写Object的equals()和toString()方法.如果两个曲目具有相同的艺术家,歌曲名称和发行年份,则视为相等.

您的类应实现可比较的接口并实现compareTo()方法.

在MP3类中,实现一个ArrayList的曲目,可以对其进行排序和搜索,添加和删除. (在现实世界中,初始化是从文件完成的,但在这种情况下,只需硬编码一些轨道即可.)
用户应该能够搜索流行歌曲或歌手.用户应该能够添加新的轨道,但是程序应该报告该轨道是否已经存在. (不允许重复).

用户应该能够创建随机曲目的播放列表.用户应该能够指定播放列表中的曲目数量,并且再次不允许重复.创建播放列表时,应在屏幕上显示每个曲目的详细信息,并显示播放列表的总播放时间.

创建MP3播放器后,其容量应为MB.用户应该能够随时检查已用空间和可用空间.达到容量上限时,无法添加其他歌曲.

歌曲应首先按艺术家排序,然后按歌曲标题排序.

歌曲应该可以在歌手或标题上进行搜索.

到目前为止,我已输入以下内容:

I have a college assignment to do and I have written up some code, but its not great and not working, I am wondering is there a sample code that I could use/follow to give me an idea on how to get the assignment started.

Assignment Question:

Write a program that will implement some functionality of a simple MP3 player. You should develop a program that allows us to add, remove, sort and search a collection of music tracks. Each track is characterised by artist, song title, release year, time and size (in MB). All attributes should be initialised when the object is created.

Your class should override the equals () and toString () methods of Object. Two tracks are considered equal if they have the same artist, song title and release year.

Your class should implement the comparable interface and implement the compareTo () method.

In the MP3 class, implement an ArrayList of tracks that can be sorted and searched, added to and deleted. (In a real world situation the initialization would be done from a file – but in this case just hardcode a few tracks in.)
The user should be able to search for a popular song, or artist. The user should be able to add a new track, but the program should report if the track already exists. (Duplicates not allowed).

The user should be able to create a playlist of random tracks. The user should be able to specify the number of tracks in the playlist and again no duplicates allowed. When the playlist is created the details of each track should be displayed on screen and the total playing time of the playlist should be displayed.

When the MP3 player is created it should have a capacity in MB. The user should be able to check the used and free space at any time. When the capacity has been reached no further songs can be added.

Songs should be sorted by artist first, then by the song title.

Songs should be able to be searched on Artist or Title.

This what i have typed so far:

public class MP3
{

	private String name;
	private String title;
	private int year;
	private double time;
	private double capacity;
	
	public MP3()
	{
		time =0.00;
		capacity=0.00;	
	}
	public void freeSpace()
	{
	  capacity = 0.0;
	} 
	public void usedSpace()
	{
		capacity = 0.0;
	}
	
	public String getName()
	{
		return name;
	}
	public String getTitle()
	{
		return title;
	}
	public int getYear()
	{
		return year;
	}
	public double getCapacity()
	{
		return capacity;
	}

	public String toString()
   {
  		return("name:" + name + "title:" +title+ "year:" +year+ "storagecapacity:" + capacity + "time:" + time+ "capacity in MB:" +capacity);
   }
	public double compareTo(otherMP3.capacity)
	{
		if(capacity.compareTo(otherMP3.capacity) <0)
			return -1;
		else if (capacity.compareTo(otherMP3.capacity) == 0)
			return 0;
		else
			return 1;
	}
}


我收到的错误:


The error i received:

MP3.java:45: error: <identifier> expected
	public double compareTo(otherMP3.capacity)
	                                         ^
MP3.java:56: error: class, interface, or enum expected
}
^</identifier>

推荐答案

您的函数compareTo返回int 值-您的函数标头说明了double.

因此,请更改它:
Your Function compareTo is returning a int value - your function header is stating a double.

so change it:
public double compareTo(otherMP3.capacity) {
  if(capacity.compareTo(otherMP3.capacity) <0) return -1.0; // making sure the number is understood as a double
  else if (capacity.compareTo(otherMP3.capacity) == 0) return 0.0;
  else return 1.0;
}


这篇关于Java初学者寻求帮助(创建一个简单的MP3播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆