I'm having trouble storing values into my monthlySales
array. Also, how can I retrieve the values to use in other methods such as totalSales
? Plus, I have errors in getSales()
method.
import java.util.Scanner;
import java.text.DecimalFormat;
public class SalesTracking
{
static DecimalFormat f = new DecimalFormat ("$#,##0.00");
static Scanner input = new Scanner (System.in); //create a scanner object that reads from the keyboard (System.in)
private static final double[] monthlySales = new double[12]; //create monthlysales array
private static final String[] monthArray = {"January" , "February" , "March" , "April", "May",
"June", "July", "August", "September", "October",
"November", "December"}; //create 12-month array
static void getSales(){
int size = monthArray.length;
for (int i = 0; i < size; i++){
System.out.print("Please Enter Sales for " + monthArray[i] + ":");
monthlySales[i] = input.nextDouble();
} //get sales method to store values into monthlysales
}
public static void main(String[] args){
getSales();
totalSales();
computeHighestMonth(monthlySales);
computeLowestMonth(monthlySales);
getSales()
is a method inside themain()
method. You can't do that!getSales
is declared within another method, you can't do this Java, you need to move so it's out side of the method