I need help to create a program that will accumulated sales for any given month.
The total for each month will be stored in an array. There can be more than one entry for any given month and they do not have to be entered in any order.
After all data has been entered, display the name of the month and its total sales. Accumulate each of the monthly totals into a yearly total and display the yearly total sales and the average monthly sales for the year.
the user will enter the month and sales.
That what I have so far.
I need it a soon as possible.
thank you`Inline Code Example Here`

``````public static void main(String[] args) {
// TODO code application logic herepublic static double computeAverageSales(double monthlySales[]) {
Scanner keyboard = new Scanner(System.in);

String [] monthArray = {
"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"};
int month;
double averageSale;
double sum = 0.0;
char question;
double[]sales=new double[12];

do{

int i=1;
System.out.println("Enter  Month:"   );
month = keyboard.nextInt();
System.out.println("Enter Sales for this Month:"   );
sales[i]=keyboard.nextDouble();
question =0;
System.out.println("Enter more sales Y/N:"  );
question=keyboard.next().charAt(0);

sum +=sales[i];

}
while ( question == 'Y');

System.out.println("totale sales :"+ sum  );
System.out.println("Average sales :"+ sum/12  );

}
}``````

## All 3 Replies

Write the solution in pseudo code first - the exact steps and processes you need to follow to get the correct answer, and then write the code to reflect that. DO NOT start with code! People keep asking me why I spend so much time on analysis and design (and stuff like this). My answer is simple - I take 80% of the time to model the problem correctly, then I can write the code in a day or two! And it will work the first time... After 35 years as a professional software engineer, I can say without exception that this is the best approach. Other engineers will write the code in a couple of days, and then spend twice as much time on re-design and bug fixing than I did on the design/analysis phase in the first place!

Thank you for all the informations.
This is my first java class, I try to learn as much as I can,I spent more than to weeks to create this program but I coudn't that why I asked for help.

rubber man is right. Start by getting the logic right in your head or on a sheet of paper. Doesn't matter how you write that down. When you have that clear in your own mind, then start coding.

You didn't say what is your exact problem, or what help you need exactly. But I did notice that line 19 you read the month number into a varsiable called month, but on line 21 you use i instead of month.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.