/* Problem 3 page 174 of the text * * The manager of a football stadium wants you to write a program that * calculates the total ticket sales after each game. There are four types * tickets - box, sideline, premium, and general admission. After each game * data is stored in a file in the following form: * * TicketPrice numberOfTicketsSold * * 250 5750 * 100 28000 * 50 35750 * 25 18750 * * The first line indicates that the box ticket price us $250 and that 5750 * tickets were sold at that price. Output the number of ticket sold and the * total sale amount. * */ import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import java.text.NumberFormat; class TotalTicketSales { public static void main(String [] args) throws IOException{ int ticketPrice, ticketsSold, ticketTotal; double totalSale; Scanner inFile = new Scanner(new FileReader("tickets.dat")); ticketPrice = inFile.nextInt(); ticketsSold = inFile.nextInt(); ticketTotal = ticketsSold; totalSale = ticketPrice * ticketsSold; ticketPrice = inFile.nextInt(); ticketsSold = inFile.nextInt(); ticketTotal += ticketsSold; totalSale += ticketPrice * ticketsSold; ticketPrice = inFile.nextInt(); ticketsSold = inFile.nextInt(); ticketTotal += ticketsSold; totalSale += ticketPrice * ticketsSold; ticketPrice = inFile.nextInt(); ticketsSold = inFile.nextInt(); ticketTotal += ticketsSold; totalSale += ticketPrice * ticketsSold; NumberFormat nf = NumberFormat.getCurrencyInstance(); System.out.println("Total Sales " + nf.format(totalSale)); System.out.println("Total Tickets Sold " + ticketTotal); inFile.close(); } }