In: Computer Science
Write java program that reads daily sales for 30 days until -1 is entered and find and display the following:
a) average sales for 30 days.
b) number of days that daily sales over $5000.00
import java.util.*;
public class Main
{
public static void main(String[] args)
{
//variable declaration
int days, count;
float sum, average, sales;
Scanner sc = new Scanner(System.in);
//variable initialization
sum = 0;
days = 0;
count = 0;
while(true)
{
//get user input
System.out.print("Sales of day
"+(days+1)+": ");
sales = sc.nextInt();
//break the loop if sales is
-1
if(sales == -1)
break;
//calculate the sum
sum = sum + sales;
//count the sales over 5000
if(sales>5000)
count++;
//increment the days by one
days++;
}
//calculate the average
average = sum / days;
//display the result
System.out.println("\nAverage sales for "+days+" days
= "+average);
System.out.println("The number of days that sales over
$5000.00: "+count);
}
}
OUTPUT:
Sales of day 1: 23424
Sales of day 2: 1000
Sales of day 3: 30000
Sales of day 4: 40000
Sales of day 5: 6000
Sales of day 6: 434
Sales of day 7: 455
Sales of day 8: 6767
Sales of day 9: 7878
Sales of day 10: 454
Sales of day 11: 233
Sales of day 12: 454
Sales of day 13: 57
Sales of day 14: 65
Sales of day 15: 767
Sales of day 16: 7
Sales of day 17: 67
Sales of day 18: 77
Sales of day 19: 676
Sales of day 20: 45
Sales of day 21: 322
Sales of day 22: 12
Sales of day 23: 54
Sales of day 24: 65
Sales of day 25: 76
Sales of day 26: 87
Sales of day 27: 98
Sales of day 28: 43
Sales of day 29: 65
Sales of day 30: 200
Sales of day 31: -1
Average sales for 30 days = 3996.0667
The number of days that sales over $5000.00: 6