HELP! I am creating a simple MP3 player and have an error dont know how to fix it
Code java:
public class MP3
{
private String name;
private String title;
private int year;
private double time;
private double capacity;
public MP3()
{
time =0.0;
capacity=0.0;
}
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;
}
}
Re: HELP! I am creating a simple MP3 player and have an error dont know how to fix it
Your posted code is pretty much unreadable with your attempt to color the lines, and this may prevent folks from helping you. Consider
- editing your original post and re-posting your code without attempts to color the lines
- post your actual error messages
- add a few sentences explaining your problem for us.
Re: HELP! I am creating a simple MP3 player and have an error dont know how to fix it
Sorry, its my first time posting something on this forum.
MP3.java:45: error: <identifier> expected
public double compareTo(otherMP3.capacity)
^
1 error
I have to do the following program for a college assignment. I have just started to write the program and when i went to compile it an error came up.
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.
Re: HELP! I am creating a simple MP3 player and have an error dont know how to fix it
The compiler is complaining that the method parameter doesn't make sense:
Code :
public double compareTo(otherMP3.capacity)
You'll want to check out tutorials on how to declare method parameters, but in general you declare it like a variable with parameter type followed by a parameter name. using just otherMP3.capacity doesn't make much sense.
That the parameter type should be MP3 or object depending on whether you're using generics or not, and you will want to call it otherMp3 or something similar. Then in the method body, get its capacity field's value and use it for comparison. Also, this method should return an int, not a double as you've defined it. Also, your instructions state that the class should implement the Comparable, and you will want to do this. If you're using a generic Comparable<MP3> interface, then again the method parameter will be MP3, and if not, the method parameter will be object, and you must cast it to MP3 inside of the method.