Write a program using an array that will process sales data for a week. Create a
ID: 3818338 • 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 Wekk
{
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[7]; // variable initialisation
String week[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int i,total,max,min;
total=0;
max=0;
min=0;
int m,n;
m=0;
n=0;
for(i=0;i<7;i++)
{
System.out.println("Enter the sales for Day "+(i+1)+":"); //taking sales input of each day from user
arr[i]=sc.nextInt();
total=total+arr[i]; // calculating the weeks total sale
}
for(i=0;i<7;i++)
{
if(arr[i]>max) //checking for the day having maximum sale
{
max=arr[i];
m=i;
}
else
{
min=arr[i]; //checking for the day having minimum sale
n=i;
}
}
System.out.println("Total sales of the week "+total); //displaying the details
System.out.println("Day of the week with highest sale is "+week[m]);
System.out.println("Day of the week with lowest sale is "+week[n]);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.