在Java中完成销售跟踪程序时遇到问题

在Java中完成销售跟踪程序时遇到问题,java,Java,所以我正在做一项作业,我大部分时间都完成了。不幸的是,实现最终的方法失败了。我不确定我只是没有正确初始化变量还是什么。如果我单独测试其他每个方法,那么它将准确地显示我需要的内容,但是让displaySalesInfo方法工作似乎超出了我的能力。如有任何建议,将不胜感激 public class SalesTracking { public static void main(String[] args) { // declare arrays Strin

所以我正在做一项作业,我大部分时间都完成了。不幸的是,实现最终的方法失败了。我不确定我只是没有正确初始化变量还是什么。如果我单独测试其他每个方法,那么它将准确地显示我需要的内容,但是让displaySalesInfo方法工作似乎超出了我的能力。如有任何建议,将不胜感激

public class SalesTracking {

    public static void main(String[] args) {

        // declare arrays
        String[] monthArray = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
        double[] monthlySales = new double[12];

        int highestMonth = computeHighestMonth(monthlySales), lowestMonth = computeLowestMonth(monthlySales);
        double totalSales = computeTotalSales(monthlySales), averageSales = computeAverageSales(monthlySales), highestSales = monthlySales[highestMonth], lowestSales = monthlySales[lowestMonth];           




        //call methods
        getSales(monthArray, monthlySales);
        //computeTotalSales(monthlySales);
        //computeAverageSales(monthlySales);
        //computeHighestMonth(monthlySales);
        //computeLowestMonth(monthlySales);
        displaySalesInfo(totalSales, averageSales, highestMonth, highestSales, lowestMonth, lowestSales);

    } //end main

    public static void getSales(String monthArray[], double monthlySales[]) {

        //prepare for input
        Scanner input = new Scanner(System.in);

        //input sales
        for(int i = 0; i < monthlySales.length; i++) {

            //System.out.print("Enter sales for " + monthArray[i] + ": ");
            monthlySales[i] = input.nextDouble();

        } //end for

    } //end getSales

    public static double computeTotalSales(double monthlySales[]) {

        double totalSales = 0;

        for(int i = 0; i < monthlySales.length; i++) {

            totalSales += monthlySales[i];

        } //end for

        //System.out.println("Yearly Total: " + totalSales);
        return totalSales;

    } //end computeTotalSales

    public static double computeAverageSales(double monthlySales[]) {

        double total = 0;

        for(int i = 0; i < monthlySales.length; i++) {

            total += monthlySales[i];

        } //end for

        double averageSales = total / monthlySales.length;

        //System.out.println("Average Sales: " + averageSales);
        return averageSales;

    } //end computeAverageSales

    public static int computeHighestMonth(double monthlySales[]) {

        int highestMonth = 0;
        double highestSales = monthlySales[0];

        for(int i = 0; i < monthlySales.length; i++) {

            double maxNumber = monthlySales[i];

            if(maxNumber > monthlySales[highestMonth]) {

                highestMonth = i;

            } //end if

            if(highestSales < monthlySales[i]) {

                highestSales = monthlySales[i];

            } //end if

        } //end for

        //System.out.println("The highest month is: " + highestMonth);
        //System.out.println("The highest sales amount was: " + highestSales);
        return highestMonth;

    } //end computeHighestMonth

    public static int computeLowestMonth(double monthlySales[]) {

        int lowestMonth = 11;
        double lowestSales = monthlySales[0];

        for(int i = 0; i < monthlySales.length; i++) {

            double minNumber = monthlySales[i];

            if(minNumber < monthlySales[lowestMonth]) {

                lowestMonth = i;

            } //end if

            if(lowestSales > monthlySales[i]) {

                lowestSales = monthlySales[i];

            } //end if

        } //end for

        //System.out.println("The lowest month is: " + lowestMonth);
        //System.out.println("The lowest sales amount was: " + lowestSales);
        return lowestMonth;

    } //end computeLowestMonth

    public static void displaySalesInfo(double totalSales, double averageSales, int highestMonth, double highestSales, int lowestMonth, double lowestSales) {

        System.out.println("Yearly Total: " + totalSales);
        System.out.println("Average Sales: " + averageSales);
        System.out.println("The highest month is: " + highestMonth);
        System.out.println("The highest sales amount was: " + highestSales);
        System.out.println("The lowest month is: " + lowestMonth);
        System.out.println("The lowest sales amount was: " + lowestSales);

    } //end displaySaleInfo

} //end class
公共类SalesTracking{
公共静态void main(字符串[]args){
//声明数组
字符串[]蒙塔里={“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”};
双倍[]月销售额=新双倍[12];
int highestMonth=computeHighestMonth(monthlySales),lowerstmonth=computelowerstmonth(monthlySales);
双倍总销售额=计算总销售额(月销售额),平均销售额=计算平均销售额(月销售额),最高销售额=月销售额[最高月份],最低销售额=月销售额[最低月份];
//调用方法
getSales(Monthharray、monthlySales);
//强制销售(每月销售);
//计算平均销售额(月销售额);
//计算最高月份(月数);
//计算不足一个月(月);
显示销售信息(总销售额、平均销售额、最高月份、最高销售额、最低月份、最低销售额);
}//末端总管
public static void getSales(字符串monthharray[],双月数[]){
//准备输入
扫描仪输入=新扫描仪(System.in);
//进货销售
对于(int i=0;imonthlySales[最高月份]){
最高月份=i;
}//如果结束,则结束
if(最高销售额<月销售额[i]){
最高销售额=月销售额[i];
}//如果结束,则结束
}//结束
//System.out.println(“最高月份为:“+最高月份”);
//System.out.println(“最高销售额为:“+最高销售额”);
回归最高月份;
}//结束computeHighestMonth
公共静态int computeLowestMonth(双月销售[]){
int lowestMonth=11;
双倍最低销售额=月销售额[0];
对于(int i=0;i月销售额[i]){
最低销售额=月销售额[i];
}//如果结束,则结束
}//结束
//System.out.println(“最低月份为:“+最低月份”);
//System.out.println(“最低销售额为:“+最低销售额”);
返回下个月;
}//结束computeLowestMonth
public static void displaySalesInfo(双倍总销售额、双倍平均销售额、整数最高月销售额、整数最低月销售额、整数最低月销售额){
System.out.println(“年度总额:+总销售额”);
System.out.println(“平均销售额:+averageSales”);
System.out.println(“最高月份为:“+最高月份”);
System.out.println(“最高销售额为:“+最高销售额”);
System.out.println(“最低月份为:“+最低月份”);
System.out.println(“最低销售额为:“+最低销售额”);
}//end displaySaleInfo
}//结束类

你应该打电话给getSales(Monthharray,monthlySales)在计算其他数字之前

 getSales(monthArray, monthlySales); // call this before otheres
 int highestMonth = computeHighestMonth(monthlySales), lowestMonth = computeLowestMonth(monthlySales);
 double totalSales = computeTotalSales(monthlySales), averageSales = computeAverageSales(monthlySales), highestSales = monthlySales[highestMonth], lowestSales = monthlySales[lowestMonth];
你的编程技术很差。可读性较差。我推荐以下代码

// declare arrays
String[] monthArray = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
        "October", "November", "December" };
double[] monthlySales = new double[12];
getSales(monthArray, monthlySales);
int highestMonth = computeHighestMonth(monthlySales);
int lowestMonth = computeLowestMonth(monthlySales);
double totalSales = computeTotalSales(monthlySales);
double averageSales = computeAverageSales(monthlySales);
double highestSales = monthlySales[highestMonth];
double lowestSales = monthlySales[lowestMonth];

您必须调用
getSales(monthharray,monthlySales)在计算其他数字之前

 getSales(monthArray, monthlySales); // call this before otheres
 int highestMonth = computeHighestMonth(monthlySales), lowestMonth = computeLowestMonth(monthlySales);
 double totalSales = computeTotalSales(monthlySales), averageSales = computeAverageSales(monthlySales), highestSales = monthlySales[highestMonth], lowestSales = monthlySales[lowestMonth];
你的编程技术很差。可读性较差。我推荐以下代码

// declare arrays
String[] monthArray = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
        "October", "November", "December" };
double[] monthlySales = new double[12];
getSales(monthArray, monthlySales);
int highestMonth = computeHighestMonth(monthlySales);
int lowestMonth = computeLowestMonth(monthlySales);
double totalSales = computeTotalSales(monthlySales);
double averageSales = computeAverageSales(monthlySales);
double highestSales = monthlySales[highestMonth];
double lowestSales = monthlySales[lowestMonth];

我看没问题。有什么错误吗?发生了什么事?发布一篇文章,你应该把错误日志放在上面,以帮助其他人发现问题。我看不出有问题。有什么错误吗?发生了什么事?发布一篇文章,你应该把错误日志放在上面,以帮助其他人发现问题。哇!“非常糟糕”似乎有点苛刻。我对这个还是有点陌生,这是我在这个网站上的第一篇帖子。不过,我非常感谢您的帮助,我会考虑您的可读性建议。谢谢你。@Karlnage恕我直言——反正我们都只是匿名的网名。哇!“非常糟糕”似乎有点苛刻。我对这个还是有点陌生,这是我在这个网站上的第一篇帖子。不过,我非常感谢您的帮助,我会考虑您的可读性建议。谢谢你。@Karlnage恕我直言——不管怎样,我们都只是匿名的网名。