I need to help writing this program, as it ask for a text filethat you have to c
ID: 3607806 • Letter: I
Question
I need to help writing this program, as it ask for a text filethat you have to call. if anyone has any idea, it would be reallyhelpful. . The manager of a football statium wants you to write a programthat calculates the total tickets sales after each game. There arefour types of tickets - box, sideline, premium, and generaladmission. After each game, data is stored in a file in the following form: . ticketPrice numberOfTicketsSold . . . Sample data are shown below: . 250 5750 100 28000 50 35750 25 18750 . The first line indicates that the box ticket price is $250 andthat 5750 tickets were sold at that price. Output the number oftickets sold and the total sale amount. Format your output with twodecimal places. I need to help writing this program, as it ask for a text filethat you have to call. if anyone has any idea, it would be reallyhelpful. . The manager of a football statium wants you to write a programthat calculates the total tickets sales after each game. There arefour types of tickets - box, sideline, premium, and generaladmission. After each game, data is stored in a file in the following form: . ticketPrice numberOfTicketsSold . . . Sample data are shown below: . 250 5750 100 28000 50 35750 25 18750 . The first line indicates that the box ticket price is $250 andthat 5750 tickets were sold at that price. Output the number oftickets sold and the total sale amount. Format your output with twodecimal places.Explanation / Answer
import java.util.*;
import java.io.*;
import java.text.*;
public classGrossSales
{public static void main(String[] args)throwsFileNotFoundException
{int sold, totalsold=0;
double price, total, grandtotal=0;
DecimalFormat twodecimal = new DecimalFormat("#00.00"); //format2 places
Stringformattedtotal; //strings for output
String formattedsold;
String formattedprice;
Scanner input=newScanner(new File("TicketSales.txt"));
System.out.println("Ticket Price NumberSold Total Price");
while(input.hasNextDouble()) //moredata?
{
price=input.nextDouble();
sold=input.nextInt();
total=sold*price;
totalsold+=sold;
grandtotal+=total;
formattedtotal=twodecimal.format(total); //format data
formattedsold= twodecimal.format(sold);
formattedprice= twodecimal.format(price);
System.out.println(" "+formattedprice+" "+formattedsold+" "+formattedtotal);
}
formattedtotal= twodecimal.format(grandtotal);
formattedsold= twodecimal.format(totalsold);
System.out.println(" Totals "+formattedsold+" $"+formattedtotal);
}
}