import java.util.Scanner; import java.io.*; import java.text.DecimalFormat; import javax.swing.JOptionPane; public class Ex26SalesReport { public static void main(String[] args) throws IOException { String filename; double totalSales; //Get the name of the file filename = getFileName(); //Get the total sales totalSales = getTotalSales(filename); //display the total sales displayResults(totalSales); System.exit(0); } public static String getFileName() { String file; file = JOptionPane.showInputDialog("Enter the name of the file\ncontaining days of sales amounts."); return file; } public static double getTotalSales(String filename) throws IOException { double total = 0.0; double sales; //open the file File file = new File(filename); Scanner inputFile = new Scanner(file); while (inputFile.hasNext()) { sales = inputFile.nextDouble(); total += sales; } inputFile.close(); return total; } public static void displayResults(double total) { DecimalFormat dollar = new DecimalFormat("#,###.00"); JOptionPane.showMessageDialog(null, "The total sales is $"+dollar.format(total)); } }