10 Replies - 245 Views - Last Post: 18 May 2019 - 09:38 PM Rate Topic: -----

#1 suhnasirr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-May 19

MP3 Rating Program: Creating And Calling Methods (errors)

Posted 04 May 2019 - 08:46 PM

Hi, I'm creating a program that calculates the overall rating for mp3 songs but I need to create and calls methods in my code. I have compile errors with a method and I can't seem to understand what they mean. Any help is appreciated.
import javax.swing.*;

/**
 * Author: Suha Nasir Date: May 1, 2019 Description:
 */
public class MP3Rating {

    /*
     * Display Signature Method Displays a formatted message
     */
    public static void displaySignature() {
        IO.display("**************************************\n" + "ANOTHER WONDERFUL APPLICATION \n" + " \n"
                + " By: Suha Nasir \n" + "**************************************");

    }

    /*
     * Compute MP3 Rating Method Returns a rating based on the formula in the
     * function
     */
    public static double rating(double rating) {
        int songRating = 0;
        int encodingQuality = 0;

        rating = (songRating + encodingQuality) / 2.0;

        return rating;
    }

    public static void main(String[] args) {
        int songRating = 0;
        int encodingQuality = 0;

        displaySignature();

        IO.display("This program will compute a rating for an mp3 file.");

        String fileName;

        fileName = IO.readString("Please enter the name of the mp3 file:");

        songRating = IO.readInt("Enter a rating for the song in " + fileName + " (1-10):");

        while (songRating < 1 || songRating > 10) {
            songRating = IO.readInt("Error." + "\nNumber must be in range 1-10." + "\nPlease try again.");
        }

        encodingQuality = IO.readInt("Enter a rating for the mp3 quality of " + fileName + " (1-10):");

        while (encodingQuality < 1 || encodingQuality > 10) {
            encodingQuality = IO.readInt("Error." + "\nNumber must be in range 1-10." + "\nPlease try again.");
        }

        rating(); // compile error

        IO.display(fileName + " has an overall rating of: " + rating); // compile error

    }

}



2 errors found:
File: C:\Users\guddu301\Desktop\Computer Science\Unit 4\Lab 6\MP3Rating.java [line: 59]
Error: method rating in class MP3Rating cannot be applied to given types;
required: double
found: no arguments
reason: actual and formal argument lists differ in length
File: C:\Users\guddu301\Desktop\Computer Science\Unit 4\Lab 6\MP3Rating.java [line: 61]
Error: cannot find symbol
symbol: variable rating
location: class MP3Rating

This post has been edited by g00se: 05 May 2019 - 03:58 AM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: MP3 Rating Program: Creating And Calling Methods (errors)

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 04:03 AM

Your rating() method is not designed correctly (nor is it being called correctly as it stands, hence the error)

What do you need to put into a method that rates the mp3 in order to produce the rating figure output?
Was This Post Helpful? 0
  • +
  • -

#3 suhnasirr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-May 19

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 05:55 AM

View Postg00se, on 05 May 2019 - 04:03 AM, said:

Your rating() method is not designed correctly (nor is it being called correctly as it stands, hence the error)

What do you need to put into a method that rates the mp3 in order to produce the rating figure output?


In the rating method, I am supposed to calculate how to get the overall MP3 rating which is the equation:

rating = (songRating + encodingQuality) / 2.0;

Then I am supposed to call that rating method into the main method after prompting for the song rating and encoding quality. And lastly display the output.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 06:30 AM

OK, so you need to pass songRating and encodingQuality as parameters, don't you?
Was This Post Helpful? 0
  • +
  • -

#5 suhnasirr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-May 19

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 07:50 AM

View Postg00se, on 05 May 2019 - 06:30 AM, said:

OK, so you need to pass songRating and encodingQuality as parameters, don't you?


Yes.
Was This Post Helpful? 0
  • +
  • -

#6 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 09:28 AM

So of course you'll need to make the method accept those parameters
Was This Post Helpful? 0
  • +
  • -

#7 suhnasirr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-May 19

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 09:47 AM

View Postg00se, on 05 May 2019 - 09:28 AM, said:

So of course you'll need to make the method accept those parameters


How would that be done? Sorry, I'm still a beginner in programming.
Was This Post Helpful? 0
  • +
  • -

#8 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 10:17 AM

If you don't know the answer to that then you're attempting to write code before you know enough. I would start with some basic tutorials:
https://docs.oracle....OO/methods.html
Was This Post Helpful? 0
  • +
  • -

#9 suhnasirr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-May 19

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 10:21 AM

View Postg00se, on 05 May 2019 - 10:17 AM, said:

If you don't know the answer to that then you're attempting to write code before you know enough. I would start with some basic tutorials:
https://docs.oracle....OO/methods.html


Thank you for the help, appreciate it.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14987
  • View blog
  • Posts: 59,840
  • Joined: 12-June 08

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 05 May 2019 - 10:43 AM

You have this function, right? It has a parameter for a double variable.
21	    public static double rating(double rating) {



You do not provide a double to it here. Hence the error.
54	        rating(); // compile error


Also that function RETURNS a double, and line 54 doesn't have a variable to receive that return value.
Was This Post Helpful? 0
  • +
  • -

#11 MrDaveForDays   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-May 19

Re: MP3 Rating Program: Creating And Calling Methods (errors)

Posted 18 May 2019 - 09:38 PM

hey man, i see a couple issues with the current method call:

you are calling it like this:

rating()


But the method "rating" takes in a double as a parameter. This is how you should be calling it. However you don't seem to use that double anywhere in the function. Here's an example of how I would write your rating function:

public static double rating(int songRating, int encodingQuality) 
{
    double ratingToReturn = 0.0;
    ratingToReturn = ((1.0*songRating) + encodingQuality) / 2;
    return ratingToReturn;
}




Then you can call your rating function this way:

double songRating = rating(yourSongRating, yourEncodingQuality);//pass in your song rating and your encoding quality for the song



Then afterwards you can output it similarly to how you have it right now, but just change the variable name:

IO.display(fileName + " has an overall rating of: " + rating); //im assuming this will print to the console for you?



Sorry, for that last part the code should actually look like this:

IO.display(fileName + " has an overall rating of: " + songRating); //im assuming this will print to the console for you? use whatever variable you declared above



Don't be discouraged, starting to learn programming is hard! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1