私は課題に取り組んでいます。残念なことに、最終的な方法の実装は成功していません。変数を正しく初期化していないのか、何を正しく初期化していないのか分かりません。私は他のメソッドのそれぞれを個別にテストすると、私はそれが必要なものを正確に表示しますが、displaySalesInfoメソッドを動作させることが私を超えているようです。どんな提案も大歓迎です。Javaで販売トラッキングプログラムを終了する際に問題が発生しました
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
問題はありません。何か間違いはありますか?何が起こっている? Post a [mcve] – Idos
他人が問題を見つけるのを助けるために、エラーログを置くべきです。 –