Section 3 sclass such a program that will read in a set of team nanes their wins
ID: 3728114 • Letter: S
Question
Section 3 sclass such a program that will read in a set of team nanes their wins, and their losses Sample output Lab 08, written By Your Name> Team W L 93 69 New York 87 75 Kansas City 95 67 88 74 86 76 Toronto Texas Houston Kansas city has the most wins with a winning pct of e.586 End of program. Each record in the standings.txt file is 16 characters long and has the following format: name : ..11 wins: 12. .14 losses: 15. .17 open standings file for input print column headings while(not EOF): read standingsRec; parse name from standingsRec parse wins from standingsRec parse losses from standingsRec print name, wins, losses if maxwinsExplanation / Answer
package Chegg_3; import java.io.*; import java.util.ArrayList; import java.util.stream.Stream; public class WinsAndLosses { int maxWins = 0; double maxWinPct = 0; String maxName = ""; public void readFile() throws Exception{ // String fileName = "C:\Users\Aakanksha\Desktop\standings.txt"; File file = new File("C:\Users\Aakanksha\Desktop\standings.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String st; while ((st = br.readLine()) != null) { System.out.println(st); } } public void writeOutput() { System.out.println("Team W L ---------- --- ---"); } public void getTeamNameFromFile() throws Exception{ String TeamName; File file = new File("C:\Users\Aakanksha\Desktop\standings.txt"); // This will reference one line at a time BufferedReader br = new BufferedReader(new FileReader(file)); String st; char[] line = new char[11]; ArrayList NameArrayList = new ArrayList(); ArrayList WinsArrayList = new ArrayList(); ArrayList LossesArrayList = new ArrayList(); while ((st = br.readLine()) != null) { String name = st.substring(0,11); int wins = Integer.parseInt(st.substring(12,14)); int losses = Integer.parseInt(st.substring(15,17)); NameArrayList.add(name); WinsArrayList.add(wins); LossesArrayList.add(losses); } Object[] winsArray = WinsArrayList.toArray(); Object[] lossArray = LossesArrayList.toArray(); for(int j = 0;j "-").limit(str.length()).forEach(System.out::print); System.out.println(" " + str ); Stream.generate(() -> "-").limit(str.length()).forEach(System.out::print); } public static void main(String[] args) throws Exception{ WinsAndLosses w = new WinsAndLosses(); // w.readFile(); w.writeOutput(); w.readFile(); w.getTeamNameFromFile(); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.