Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java help

  • 15-04-2016 08:04PM
    #1
    Closed Accounts Posts: 191 ✭✭


    Hi can someone please tell me why I have an error in my averageTemp method? Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,917 ✭✭✭mightyreds


    Hi can someone please tell me why I have an error in my averageTemp method? Thanks

    Do you have the method


  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    Sorry i forgot to include my code...

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    double temp [] = new double [6];

    for (int i=0; i<6; i++){
    double degree = Double.parseDouble(JOptionPane.showInputDialog("Enter the temperatures for the six months..."));
    double number = temp;
    }
    tempConvert(temp);
    double average = averageTemp(temp);


    }
    public static void tempConvert (double x[]){
    for (int i=0; i<x.length; i++){
    double F = 9 / 5 * i + 32;

    }
    public static double tempConvert (double y[]) {
    for (int count=0; count < y.length; count++){
    double sum = temp +=


    }
    }
    }
    }


  • Registered Users, Registered Users 2 Posts: 1,267 ✭✭✭00sully


    Hi can someone please tell me why I have an error in my averageTemp method? Thanks

    Probably...

    "NoSuchMethodError"

    :pac:


  • Registered Users, Registered Users 2 Posts: 2,917 ✭✭✭mightyreds


    As sully has pointed out you forgot the average temp code

    Plus the last line doesn't seem to be doing anything


  • Registered Users, Registered Users 2 Posts: 1,469 ✭✭✭Anesthetize


    You have two methods called tempConvert but no averageTemp method.

    Also for readability use code tags when posting code.


  • Advertisement
  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    I am aware The last line isn't finished I just want to get my methods working before I carry on. What do ye mean by my method is non existent, can ye please explain


  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    I see what ye mean, I have changed my second method to average temp but still the same error.


  • Registered Users, Registered Users 2 Posts: 2,917 ✭✭✭mightyreds


    Any an average method I'd usually go

    For int I=0; i<temp.length; i++
    Total+= temp(I)
    End for
    Average = total/temp.length-1
    Return average


    Could be wrong though I'm fairly drunk, that's all over the place cause I'm on my moblie too


  • Registered Users, Registered Users 2 Posts: 1,469 ✭✭✭Anesthetize


    I am aware The last line isn't finished I just want to get my methods working before I carry on. What do ye mean by my method is non existent, can ye please explain
    You code above is calling a method called averageTemp, but you haven't implemented the code for this method.


  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    I have the errors in these parts "double temperature = averageTemp(temp) and "public static double averageTemp(double y)" both errors are under "averageTemp


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,917 ✭✭✭mightyreds


    Will it not compile post the errors if you hover over the code


  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    Multiple markers at this line
    -syntax error on token "(",; expected
    - illegal modifier for parameter averageTemp; only final is permitted
    - syntax error on token")",; expected


  • Closed Accounts Posts: 191 ✭✭chocolate boy123


    Here is a pic


  • Registered Users, Registered Users 2 Posts: 306 ✭✭yes there


    Can someone delete this thread because this is just ridiculous and an embarrassment to have in the forum.


Advertisement