import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class BowlerReader { private static final String FILE_NAME...

Free

70.2K

Verified Solution

Question

Programming

import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;public class BowlerReader {  private static final String FILE_NAME = \"bowler.txt\";  public static void main(String[] args) throws FileNotFoundException {    System.out.println(\"Reading Data from file\");      Scanner fileReader = new Scanner(new File(FILE_NAME));      System.out.printf(\"%-20s%-10s%-10s%-10s%-10s\n\", \"Sample Data\", \"Game 1\", \"Game 2\", \"Game 3\", \"Average\");      int bowler = 1;      while (fileReader.hasNext()) {        String scores[] = fileReader.nextLine().split(\"\\s+\");        double average = Integer.parseInt(scores[0]) + Integer.parseInt(scores[1]) + Integer.parseInt(scores[2]);        average /= 3;        System.out.printf(\"%-20s%-10s%-10s%-10s%-10.2f\n\", \"Bowler \" + bowler, scores[0], scores[1], scores[2], average);        bowler += 1;      }      fileReader.close();    }}

(How can you edit the following source code, I dont wanna usefilenotfound but throws ioexception. also i cant use split. pleasemodify these two details for me. Can't use a method or advancedknowledge.

Answer & Explanation Solved by verified expert
3.8 Ratings (362 Votes)

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class BowlerReader {

   private static final String FILE_NAME = \"bowler.txt\";

   public static void main(String[] args) throws IOException {

       System.out.println(\"Reading Data from file\");

       Scanner fileReader = new Scanner(new File(FILE_NAME));

       System.out.printf(\"%-20s%-10s%-10s%-10s%-10s\n\", \"Sample Data\", \"Game 1\", \"Game 2\", \"Game 3\", \"Average\");
       int bowler = 1;
       while (fileReader.hasNext()) {
           //reading scores for a bowler
           int s1=fileReader.nextInt();
           int s2=fileReader.nextInt();
           int s3=fileReader.nextInt();

           double average = s1+s2+s3;
           average =average/ 3.0;
           System.out.printf(\"%-20s%-10s%-10s%-10s%-10.2f\n\", \"Bowler \" + bowler, s1,s2,s3, average);
           bowler += 1;
       }
       fileReader.close();

   }


}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students