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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 18:00, markleal9484
What ordering of tcp flags makes up the three-way handshake?
Answers: 2
image
Computers and Technology, 22.06.2019 15:30, gudon986732
When creating a budget, log fixed expenses before income. after income. after savings. at the top.
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, hannahliebl2000
Need asap write a short paper describing the history and differences between six sigma, waterfall, agile, and scrum models. understanding these models can give you a good idea of how diverse and interesting it development projects can be. describe what the rationale for them is and describe their key features. describe the history behind their development. at least 400 words
Answers: 1
image
Computers and Technology, 23.06.2019 01:20, sosick90501
Write a function balancechemical to balance chemical reactions by solving a linear set of equations. the inputs arguments are: reagents: symbols of reagents in string row array products: symbols of products in string row array elements: elements in the reaction in string row array elcmpreag: elemental composition of reactants in two dimensional numeric array elcmpprdcts: elemental composition of prducts in two dimensional numeric array hint: the first part of the problem is setting up the set of linear equations that should be solve. the second part of the problem is to find the integers from the solution. one way to do this is to mulitiply the rational basis for the nullspace by increasing larger integers until both the left-and right-side integers exist. for example, for the reaction that involves reacting with to produce and : reagents=["ch4", "o2"]; products =["co2", "h2o"]; elements =["c","h", "o"] elcmpreag=[1,4,0;
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 in other subjects:

Konu
Mathematics, 04.11.2020 01:00
Konu
Social Studies, 04.11.2020 01:00
Konu
English, 04.11.2020 01:00