Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program using an array that will process sales data for a week. Create a

ID: 3812101 • Letter: W

Question

Write a program using an array that will process sales data for a week. Create an array that will store input data for the daily sales for a week (7 days). Using the array data determine the total sales for the week, the day of the week with the least number of sales and the day of the week with the highest sales.

Be sure to submit the .java, .class files, and two test runs of the program. The program may be written in one file unless you choose to create an object and tester. Use spacing, alignment, indentation and comments to provide a easily readable code.

Explanation / Answer

import java.util.Scanner;

public class Sales {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       // creating an array

       double sales[] = new double[7];

       System.out.println("Please enter sales for 7 days: ");

       for(int i=0; i<7; i++)

           sales[i] = sc.nextDouble();

       // calculating total sale

       double total = sales[0];

       int minDay = 0; // initializing min day with first day

       int maxDay = 0;// initializing max day with first day

       for(int i=1; i<7; i++){

           total = total + sales[i];

           if(sales[minDay] > sales[i])

               minDay = i;

           if(sales[maxDay] < sales[i])

               maxDay = i;

       }

      

       System.out.println("total sale: "+total);

       System.out.println((minDay+1)+" has minimum sale");

       System.out.println((maxDay+1)+" has maximum sale");

   }

}

/*

Sample run:

Please enter sales for 7 days:

54.32 23.43 65.43 89.0 66.5 31.9 45.3

total sale: 375.88

2 has minimum sale

4 has maximum sale

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote