Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: HELP! I am creating a simple MP3 player and have an error dont know how to fix it

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Location
    Ireland
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question HELP! I am creating a simple MP3 player and have an error dont know how to fix it

     
    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;
    	}
     
    }
    Last edited by Siobhan Burke; October 21st, 2012 at 10:01 AM.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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

    1. editing your original post and re-posting your code without attempts to color the lines
    2. post your actual error messages
    3. add a few sentences explaining your problem for us.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Location
    Ireland
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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:
    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.

Similar Threads

  1. I dont see anything wrong with this(simple beginner code)
    By Olympaphibian89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 26th, 2012, 03:11 PM
  2. creating pop-ups in a 2 player game
    By bigtan in forum Java Networking
    Replies: 1
    Last Post: May 2nd, 2012, 07:28 AM
  3. Creating a new class and dont know how to generate a random number math code
    By beatlebaby70 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 15th, 2011, 03:03 PM
  4. My code have a simple error but i dont know how to solve it !!!
    By Blackhawk1993 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 17th, 2011, 01:12 PM
  5. i'm getting this error, dont know why? please help
    By amr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 17th, 2010, 06:14 AM

Tags for this Thread