1. Create a Java program toread in an unknown number of lines from a data file.
ID: 3619239 • Letter: 1
Question
1. Create a Java program toread in an unknown number of lines from a data file. This filecontains a football team’s name, the number of games theyhave won, and the number of games they have lost.
2. Process all data until itreaches the end-of-file. Calculate the win percentage for eachteam.
3. Outputto a file (“top.txt”) a listing of all teams with a winpercentage greater than .500. This file should contain theteam name and the win percentage.
4. Outputto a file (“bottom.txt”) a listing of all teams with awin percentage of .500 or lower. This file should contain theteam name and the win percentage.
5. Count and print to thescreen the number of teams with a record greater then .500 and thenumber of teams with a record of .500 and below, each appropriatelylabeled.
1. Declare thevariables.
2. Create andinitialize the variables to open the text file.
3. Read in thevalues from the file - using a loop
4. Calculate thewin percentage for each team.
5. Check for thehigh and low values - account for a tie within the teams
6. Output totop.txt file the listing of all teams with a win percentage greaterthan .500.
7. Output tobottom.txt file the listing of all teams with a win percentage .500or lower.
8. Count and printwith labels on screen the number of teams with a record greaterthan .500 and the number of teams .500 and lower.
9. Output amessage box stating Football Stats.
Explanation / Answer
please rate - thanks import java.util.*; import java.io.*; import javax.swing.*; public class FileInOut {public static void main(String[] args)throwsFileNotFoundException {int i; String filename,team,beststring="",worststring=""; int won,lost,more=0,less=0,bestcount=0,worstcount=0; String []bestname=new String[10]; String []worstname=new String[10]; double percent,best=-1,worst=2; Scanner in=new Scanner(System.in); System.out.print("Enter the name of your input file: "); filename=in.next(); Scanner input=new Scanner(new File(filename)); PrintStream outputtop=new PrintStream(new File("top.txt")); PrintStream outputbottom=new PrintStream(newFile("bottom.txt")); while(input.hasNext()) {team=input.next(); won=input.nextInt(); lost=input.nextInt(); percent=won/(double)(won+lost); if(percent>.5) {outputtop.println(team+ " "+percent); more++; if(percent>best) {bestcount=1; bestname[bestcount-1]=team; best=percent; } else if (percent==best) {bestcount++; bestname[bestcount-1]=team; } } else {outputbottom.println(team+ " "+percent); less++; if(percentRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.