subject

A comma separated value (.csv) file has been included to be used for this program. Each line contains two values, a name and a number separated by a comma (except the first line, which contains the titles for the value types). The name is that of a writer and the number refers to the number of works the writer has written. Ex. Jane Austen,6. Each line is an entry and each entry number can be updated by identifying the associated name. Once complete, the following program opens data file allWorks. csv and asks if the user wants to update entries or add new entries. All entries are stored in an array while being read in and updated. The program then writes the array to the file, overwriting the original contents. The following TODO sections must be completed.
Open allWorks. csv for reading/input.
Locate an entry to be updated by name (use the Java String indexOf() method)
Add a new entry if the name isn't found in the file (give the entry a new number)
Open file allWorks. csv for output
Write contents of the array to allWorks. csv (original file is overwritten)
Ex: If the input is:
y
J. K. Rowling
30
y
Elton John
y
62
n
and allWorks. csv originally contains:
Name, Number of Novels
Jane Austen,6
Charles Dickens,20
Ernest Hemingway,9
Jack Kerouac,22
F. Scott Fitzgerald,8
Mary Shelley,7
Charlotte Bronte,5
Mark Twain,11
Agatha Christie,73
Ian Flemming,14
J. K. Rowling,14
Stephen King,54
Oscar Wilde,1
the output in allWorks. csv is:
Name, Number of Novels
Jane Austen,6
Charles Dickens,20
Ernest Hemingway,9
Jack Kerouac,22
F. Scott Fitzgerald,8
Mary Shelley,7
Charlotte Bronte,5
Mark Twain,11
Agatha Christie,73
Ian Flemming,14
J. K. Rowling,30
Stephen King,54
Oscar Wilde,1
Elton John,62
Downloadable files: allWorks. csv
Code already supplied that needs input:
import java. util. Scanner;
import java. util. ArrayList;
import java. io. FileInputStream;
import java. io. PrintWriter;
import java. io. FileOutputStream;
import java. io. IOException;
public class DataFile {
public static void main(String[] args) throws IOException {
Scanner scnr = new Scanner(System. in);
FileInputStream inputFileStream = null; // File input stream
Scanner inFS = null; // File Scanner object
FileOutputStream outputFileStream = null;
PrintWriter outFS = null;
String lineString = ""; // Stores line-by-line input from file
char yesNo = 'n';
String updateName = "";
String updateNum = "";
String[] fileContents = new String[50]; // Array for storing and updating file contents
int size = 0;
int i = 0;
boolean entryFound = false;
System. out. println("Would you like to update allWork. csv?");
yesNo = scnr. next().charAt(0);
scnr. nextLine();
while (yesNo == 'y') {
size = 0;
System. out. println("Which entry would you like to update?");
updateName = scnr. nextLine();
while (inFS. hasNext()) {
lineString = inFS. nextLine();
if(/* TODO: Locate updateName in the file */) {
entryFound = true;
System. out. println("Enter a new value for " + updateName);
updateNum = scnr. next();
lineString = updateName + "," + updateNum;
}
// Storing each line in the array
fileContents[size] = lineString;
++size;
}
if (!entryFound) {
System. out. println("Entry not found. Add new entry?");
yesNo = scnr. next().charAt(0);
scnr. nextLine();
if(yesNo == 'y') {
System. out. println("Number of works?");
// TODO: Add new entry if the name isn't found in the file
}
}
// TODO: Open file "allWorks. csv" for output
// TODO: Write contents of the array to the allWorks. csv (original file is overwritten)
System. out. println("Would you like to continue to update allWork. csv?");
yesNo = scnr. next().charAt(0);
scnr. nextLine();
}
outputFileStream. close(); // close() may throw IOException if fails
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 11:30
Me dangers of social media and the internetexplain what each means: 1) social media and phones have become an addiction.2) outside people have access to you all the time.3) cyberstalking4) cyberbullying5) catphishing6) viruses7) identity theft8) credit card fraud9) hacking10) money schemes
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
question
Computers and Technology, 23.06.2019 21:50
Description: write function lastfirst() that takes one argument—a list of strings of the format "lastname, firstname" —and returns a list consisting of two lists: (a) a list of all the last names (b) a list of all the first names
Answers: 2
question
Computers and Technology, 23.06.2019 22:30
Lakendra finished working on her monthly report. in looking it over, she saw that it had large blocks of white space. what steps could lakendra take to reduce the amount of white space?
Answers: 3
You know the right answer?
A comma separated value (.csv) file has been included to be used for this program. Each line contain...
Questions
question
English, 11.10.2021 17:40
question
Mathematics, 11.10.2021 17:40
question
Mathematics, 11.10.2021 17:40
question
History, 11.10.2021 17:50
question
Social Studies, 11.10.2021 17:50
question
Social Studies, 11.10.2021 17:50
Questions on the website: 13722363