Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt

Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20

import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner;

public class Main1 {

private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0;

public static void main(String[] args) throws IOException { System.out.println(title); driver(); } public static void driver() throws IOException { boolean q = false; ScanInput(); Scanner scan = new Scanner(System.in); System.out.println("Please enter the file name with .txt"); String filename = scan.nextLine();

while (!q) { q = processDetail(scan, filename); } scan.close(); System.out.print("Hope you enjoy this program! /nHave a nice day!!"); }

private static boolean processDetail(Scanner scan, String filename) throws IOException { boolean q = false; System.out.println("Enter Yor Q; Y for playing; Q for quiting "); String input = scan.nextLine().trim(); if (input.equalsIgnoreCase("y") ) { System.out.println("Enter the player's full name:"); String fullname= scan.nextLine().trim(); String sss=fullname; player=sss.split(" "); double percent= ProcessInput(player[0]); if (percent <= 0) { System.out.println("Sorry! The player may not shot, or the player wasn't in the league "); return q; } else { COUNTS++; // increment the counts when data are found in the file String result = "The eFG% for "+ player[0] + "is " +percent+"in the team "+player[1] ; DATA += (COUNTS + ". " + result + " "); System.out.println(result + " will be stored in " + filename + " "); System.out.println(DATA); // myFileWriter(filename, DATA); return q; } } else if (input.equalsIgnoreCase("q") ) { q = true; return q; } else { System.out.println("WARNNING: please enter a valid input "); return q; } }

private static double ProcessInput(String fullname) {

int FGM = -1; int threePM = -1; int FGA = -1; for (int i = 0; i < player.length; i++) { String[] data = player[i].split(","); String player = data[0]; if (fullname.equalsIgnoreCase(player)) { FGM = Integer.parseInt(data[2]); threePM = Integer.parseInt(data[3]); FGA = Integer.parseInt(data[4]); } } if (FGM <= 0 || threePM <= 0 || FGA <= 0) { return -1; } else return efgCalculator(FGM, threePM, FGA); }

private static double efgCalculator(int FGM, int threePM, int FGA) { double efg = 100 * ((FGM +(threePM) * 0.5) / FGA); double efgPercent = Math.round(efg); return efgPercent; }

private static void ScanInput() throws FileNotFoundException { try { String Greeting = "Hi, here are your searching history!! "; File file = new File("input.txt"); Scanner scan = new Scanner(file); PrintWriter pw = new PrintWriter(file,"UTF-8"); int index = 0; while (scan.hasNextLine()) { player[index] = scan.nextLine(); index++; } pw.print(Greeting); pw.close(); scan.close(); } catch (FileNotFoundException e1) { System.out.println("File not found or have some typo! Checked again!"); }catch (IOException e) { System.out.println("I/O error occurs!!!"); } } }

JAVA

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago