Question

In: Computer Science

Write java program that reads daily sales for 30 days until -1 is entered and find...

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

            

Solutions

Expert Solution

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



Related Solutions

Instructions: Create a Java program that reads a string entered by the user and then determines...
Instructions: Create a Java program that reads a string entered by the user and then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also, count and print the number of non-vowel characters. Example: User enters: "This house is beautiful." a: 1 e: 2 i: 3 o: 1 u: 2 non-vowel:10
Write a Java program that reads a list of 30 fruits from the file “fruits.txt”, inserts...
Write a Java program that reads a list of 30 fruits from the file “fruits.txt”, inserts them into a string array, and sorts the array in alphabetical order. String objects can be compared using relational operators such as <, >, or ==. For example, “abc” > “abd” is false, but “abc” < “abd” is true. Sample output: Before Sorting: Cherry, Honeydew, Cranberry, Lemon, Orange, Persimmon, Watermelon, Kiwifruit, Lime, Pomegranate, Jujube, Pineapple, Durian, Plum, Banana, Coconut, Apple, Tomato, Raisin, Mandarine, Blackberry,...
Use Java (Find the number of days in a month) Write a program that prompts the...
Use Java (Find the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, If the user entered month 2 and year 2012, the program should display that February 2012 has 29 days. If the user entered month 3 and year 2015, the program should display that March 2015 has 31 days. Sample Run 1 Enter a month in the...
Write a program that reads in characters until end of file. The program should count and...
Write a program that reads in characters until end of file. The program should count and print the number of characters, printable characters, vowels, digits, and consonants in the input. Use functions to check whether a character is a vowel, a consonant, or a printable character. Define and use macros to test if a character is a digit or a letter.
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all...
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all the lyrics from a file named lyrics.txt that is to be found in the same directory as the running program. The program should read the lyrics for each line and treat each word as a token. If the line contains a double (an integer is also treated as a double) it should use the first double it finds in line as the timestamp for...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and...
(JAVA) Write an application that reads three nonzero values entered by the user and determines and prints whether they could represent the sides of a triangle. Enter three sizes, separated by spaces(decimals values are acceptable): 4.5·5.5·3.5 A triangle could measure 4.50, 5.50, by 3.50.
IN C++ Write a program that reads in int values from the user until they enter...
IN C++ Write a program that reads in int values from the user until they enter a negative number like -1. Once the user has finished entering numbers, print out the highest value they’ve entered, the lowest value they’ve entered, and the total number of numbers they’ve entered. The negative number they entered should not be taken as one of the values entered.
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT