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

The Straight Talk Bar and Grill has commissioned you to write a program to keep

ID: 3852582 • Letter: T

Question

The Straight Talk Bar and Grill has commissioned you to write a program to keep track of its daily sales. The people at the Straight Talk wish you to set up the program so that it prompts Laurie McCool, the manager, for the total sales for a day, and reads in her reply. Now, the Straight Talk does not necessarily check its sales once a week. Laurie McCool will be running the program at random intervals. This means that you can't count her entering sales for exactly six days. Therefore your program should incorporate a loop which will continue to prompt Laurie McCool for a day's total sales until she enters the number 9999. This number will be Laurie's Sentinel Signal that she is done entering the data. Be sure that your program DOESN'T INTERPRET that number as the total sales for a day! After reading in all the data, your program should print out the following information: The number of days for which data was entered. The grand total for all the sales entered. The average for all the sales entered. The best (maximum) sale and the day on which it occurred. The worst (minimum) sale and the day on which it occurred. There are several things that your program should watch out for. FIRST OF ALL, Laurie McCool often partakes of the product she sells and her typing can be erratic. The total sales for a day will always be a positive real number and if your program reads in a negative number, it should let her know that it is invalid and prompt for more data. Be sure that no negative numbers are used in your program's computation of the grand total the average, etc... Also the counter for number of days should not be incremented when negative numbers are entered. Laurie also occasionally begins to run the program and then changes her mind. In such an instance she types immediately 9999 in reply to the first prompt. Your program should handle this event without ABNORMALLY TERMINATING. Be sure that if the first number is 9999 your program does not attempt the computations of the grand total average, etc... Laurie sometimes forgets how the program works, so your output should begin with a brief description of the program. Make sure that your prompts are clear. DON'T FORGET to tell Laurie how to stop the program. All the results should be carefully explained. DO NOT USESCIENTIFIC NOTATION --- LAURIE JUST CAN'T HANDLE IT!

Explanation / Answer


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Sam
*/
public class BarSalesCalc {
  
    public static void main(String[] args) throws IOException {
      
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int count = 0;
        double sum = 0;
        int minDay = -1, maxDay = -1;
        double maxSale = Double.MIN_VALUE, minSale = Double.MAX_VALUE;
        double value;
        do {
            count = count + 1;
            System.out.println("Enter 999 as value to exit");
            System.out.println("Enter sale amount for day "+count+": ");
            value = Double.parseDouble(br.readLine());
            sum = sum + value;
            if (value!=999) {
                if (value > maxSale){
                    maxSale = value;
                    maxDay = count;
                }
                if (value < minSale){
                    minSale = value;
                    minDay = count;
                }
            }
        }while(value!=999 && value!=9999);

        if (value == 9999 || count == 1)
            return;
        sum = sum - 999;
        count --;
        double avg = sum/count;
      
        System.out.println("Total days: "+count);
        System.out.println("Total sales: "+sum);
        System.out.println("Avg sales: "+avg);
        System.out.println("Best sale was $"+maxSale+" on day "+maxDay);
        System.out.println("worst sale was $"+minSale+" on day "+minDay);
      
    }
}

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