类型 WeeklyGasAverages 未定义方法 displayLowestPrice(double[])

问题描述 投票:0回答:1

所以我想使用另一个文件中的函数,但我似乎无法使用它,因为我不断收到此错误。我猜此时它与数组有关,因为我已经尝试了其他所有方法。

import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.io.FileNotFoundException;

public class WeeklyGasAveragesTest{

    public static void main(String[] args) throws Exception{

        double[] GasArray = new double[52];
        int count = 0;

        File file = new File("C:\\Users\\Braedon\\Desktop\\Weekly_Gas_Averages.txt");
        Scanner sc = new Scanner(file);

        while (sc.hasNextLine()) {
            GasArray[count] = Double.parseDouble(sc.nextLine());
            System.out.println(GasArray[count]);
            count += 1;
        }

        WeeklyGasAverages.GasWeek.displayLowestPrice(GasArray);

    }
}
import java.util.Scanner;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.io.FileNotFoundException;
import java.time.LocalDate;
import java.time.temporal.WeekFields;


public class WeeklyGasAverages{

    public class GasWeek {

        int weekNumber,
            month;
        double price;

public displayLowestPrice(double[] list) {
            double temp = 999;
            for (int count; count < list.length; count++){
                if (temp > list[count])
                    temp = list[count];
            }
            return temp;
        }
}

“类型 WeeklyGasAverages.GasWeek 未定义方法 displayLowestPrice(double[])

    at WeeklyGasAveragesTest.main(WeeklyGasAveragesTest.java:23)"

这正是我得到的错误,我最初将 displayLowestPrice 作为双精度,将其作为静态,将之前列出的类仅作为 WeeklyGasAverages.displayLowestPrice 并尝试了 GasWeek.displayLowestPrice 。这些都不起作用,我迷失了,任何帮助将不胜感激。非常感谢你

java arraylist double
1个回答
0
投票

您有很多编译错误。阅读 IDE 警报!我修复它并写评论以进行解释。

public class WeeklyGasAverages {
public class GasWeek {
    int weekNumber, month;
    double price;

    public static double displayLowestPrice(double[] list) { //make static, add return type 'double'
        double temp = 999;
        for (int count = 0 ; count < list.length ; count++) { //init count - 'count=0';
            if (temp > list[count]) {
                temp = list[count];
            }
        }
        return temp;
    }
}}
© www.soinside.com 2019 - 2024. All rights reserved.