Question: I need help reading the name.txt file i keep getting error. i attached the code import java.io.*; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.ArrayList;
I need help reading the name.txt file i keep getting error. i attached the code

import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class FamousCS {
private String firstName;
private String lastName;
private String fame;
public FamousCS(String firstName, String lastName, String fame)
{
this.firstName = firstName;
this.lastName = lastName;
this.fame = fame;
}
public String toString() {
return firstName+""+ lastName+""+fame;
}
public static Scanner readFile() {
Scanner inputFile = null;
try {
inputFile =new Scanner(new File ("names.txt"));}catch(Exception e) {
System.out.println("Diffulties to open file"+ e);
}
return inputFile;
}
public static void writeToFile (List
if(list!=null && list.size()>0) {
try { PrintStream outputFile=new PrintStream(new File("D:\\CSReport.txt")); //accessing the file
for (FamousCS famousCS : list) {
outputFile.println(famousCS.toString()); // writing to the file
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Scanner inputFile=readFile(); // calls the readfile method
List
while(inputFile.hasNext()){ // looping to the content of the file
String famousJavaInfo=inputFile.nextLine();
String [] famousArray=famousJavaInfo.split(","); // splitting the info
FamousCS cs=new FamousCS(famousArray[1], famousArray[0], famousArray[2]); // object creation of the FamousCs
System.out.println(cs); // printing the info
list.add(cs); // adding info to list
}
writeToFile(list); // calling the function to write into a file
}
}
Gosling Knuth Hopper Booch Write a tester/controller class called FamousCS.java which reads a text file (names.txt) that contains the last name, first name, and "claim to fame" of several famous Computer Scientists. FamousCS.java and names.txt must be in the same folder (Eclipse package) 1. Read each line from the file. The items in each line are separated by commas as shown here Booch,Grady,is known as one of the developers of UML G. Booch is known as one of the developers of UML. There are Xfamous computer scientists in the file. Then, using System.out.println() display the information as follows: Count the number of famous computer scientists in names.txt and display Now, write the same output statements to an output file called CSReport.txt Search the web and find another famous computer scientist and add the information (last name first name, "claim to fame") to the input text file names.txt 2. Run FamousCS.java with your updated names.txt file 3. Submit FamousCS.java, names.txt and CSReport.txt Example output (before additional famous computer scientist added): J. Gosling is often called the inventor of Java E. Dijkstra was the supreme algorithmist- he researched and developed how to solve problems fast. A. Kaydeveloped the first OO programming languagecalled Smalltalk. R. Pausch led the team of Carnegie Mellon graduate students that developed the Alice programming language. A. Turing is often considered the father of modern computer science. J. Backus developed the Fortran language with his team at IBM D. Knuth wrote the ultimate Computer Science comprehensive text called The Art of Computer Programming. J. McCarthy is famous for his contributions to and coined the term Artificial Intelligence. G. Hopper was a Navy Admiral who invented the firstcompiler J. von Neumann developed the von Neumann architecture used in virtually every non-parallel processing computer There are 10 famous computer scientists in the file. Helpful References in the Files Modules Review Activities and solution files Checklist: Using Files in Java Opbaker
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
