简体   繁体   中英

Method(double, double) is not applicable for the arguments (double[], double[])

import java.io.*;
import java.util.*;
public class HeatIndex
{
    public static double [] loadKeyWestTemp() throws IOException//method to    read temp text file and convert to an array
{
    Scanner inFile = new Scanner(new File("KeyWestTemp.txt"));
    List<Double> array = new ArrayList<>();
    while(inFile.hasNext()){
        array.add(inFile.nextDouble());
    }
    double t[] = new double[array.size()];
    for(int i = 0; i < array.size(); i++){
        t[i] = array.get(i);
    }
    inFile.close();
    return t;
}

public static double [] loadKeyWestHumidity () throws IOException//method to read humidity text file and convert to array
{
    Scanner inFile = new Scanner(new File("KeyWestHumid.txt"));//finding text file
    List<Double> array = new ArrayList<>();//initializing Array List
    while(inFile.hasNext()){//while-loop to fill array list
        array.add(inFile.nextDouble());
    }
    double h[] = new double[array.size()];//assigning array list values to the h[] array
    for(int z = 0; z < array.size(); z++){
        h[z] = array.get(z);
    }
    inFile.close();//closing inFile
    return h;//returning h[]
}
public static double heatIndex(double t, double h){//method to calculate the Heat Index formula{
    //declaring variables that are a part of the Heat Index formula
    double H1 = -42.379;
    double H2 = 2.04901523;
    double H3 = 10.14333127;
    double H4 = 0.22475541;
    double H5 = 6.83783 * .001;
    double H6 = -5.481717 * .01;
    double H7 = 1.22874 * .001;
    double H8 = 8.5282 * .0001;
    double H9 = 1.99 * 000001;
    //the actual formula
    double index = (H1) + (H2*t) + (H3 * h) + (H4 * t * h) + (H5 * (t * t)) + (H6 * (h * h)) + (H7 *(t * t)*h) + (H8 * t *(h * h)) + (H9 * (t * t)*(h * h));
    return index;
}
public static void main(String[]args)throws IOException {//main method
    for(int y = 0; y < 11; y++){
        double HI [] = heatIndex(loadKeyWestTemp(),loadKeyWestHumidity());
        }
    }
}

I am writing a program that reads the temperatures and humidity percentages from two text files and then uses the values inside to find the Heat Index from those values. I am getting an error in the line: double HI [] = heatIndex(loadKeyWestTemp(),loadKeyWestHumidity()); It says that I am not allowed to use the a method that contains doubles with double[]. Is there a way I can fix this without having to rewrite major parts of my program? Thank you!

You need to index the elements in the double array:

double kwt = loadKeyWestTemp();
double kph = loadKeyWestHumidity();
double HI = new double[kwt.length];

for(int y = 0; y < 11; y++){
    HI[y] = heatIndex(kit[y], kph[y]);
}

This is assuming the two methods return arrays the same size (11).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM