Please don\'t use while loop to answer. use get and stuff like that. HELP ASAP t
ID: 3672613 • Letter: P
Question
Please don't use while loop to answer. use get and stuff like that. HELP ASAP thank you
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 of tickets-box, sideline, premium, and general admission. After each game, data is stored in a file in the following form: ticketPrice numberOfTicketsSold Sample data are shown below: The first line indicates that the ticket price is $250 and that 5750 tickets were sold at that price. Output the number of tickets sold and the total sale amount. Format your output with two decimal places.
Explanation / Answer
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(); }