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, 21.06.2019 17:10
Write an application that allows a user to enter the names and birthdates of up to 10 friends. continue to prompt the user for names and birthdates until the user enters the sentinel value “zzz” for a name or has entered 10 names, whichever comes first. when the user is finished entering names, produce a count of how many names were entered, and then display the names. in a loop, continuously ask the user to type one of the names and display the corresponding birthdate or an error message if the name has not been previously entered. the loop continues until the user enters “zzz” for a name. save the application as birthdayreminder.java.
Answers: 1
question
Computers and Technology, 22.06.2019 17:00
The two main ways in which marketers address the competition with their strategies are by satisfying a need better than a competition and by
Answers: 2
question
Computers and Technology, 23.06.2019 05:00
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
After you present a proposal, the committee starts asking you questions, some beyond the strict focus of your proposal. they ask questions about implications in other fields and knowledge about other fields. you are asked to redo your proposal. what is most likely missing? breadth of material depth of material clarity of material details of material
Answers: 1
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
Mathematics, 09.08.2019 01:10