/********************************************************************* * Author: Eric Heim * Date Created: 6/9/2011 * Course: CS0007 * Description: Shows the use of an sentinel value by taking in * amounts sold for a number of days and displaying their * sum and average when a sentinel value is entered *********************************************************************/ import java.text.DecimalFormat; import java.util.Scanner; public class SentinelValue { public static void main(String[] args) { int days = -1; double dayAmount = 0.0, total = 0.0; Scanner keyboard = new Scanner(System.in); DecimalFormat formatter = new DecimalFormat("0.00"); while(dayAmount != -1.0) { days++; total += dayAmount; System.out.print("Total amount sold for day " + days + " (-1 to quit): "); dayAmount = keyboard.nextDouble(); } System.out.println("Total Sales: " + formatter.format(total)); System.out.println("Average Sales Per Day: " + formatter.format(total/days)); } }