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, 22.06.2019 01:40
Kali, a python programmer, is using the turtle module to write the word “hello.” which code should she use to indicate the location to begin writing the word? a # pick up the turtle and move it to its starting location. b penup(-100, 200) goto() pendown() c penup() goto(-100, 200) pendown() d # pick up the turtle and move it to (-100, 200)
Answers: 2
question
Computers and Technology, 24.06.2019 00:40
To maintain clarity and focus lighting might be needed
Answers: 2
question
Computers and Technology, 24.06.2019 06:30
For which utilities, if any, does the landlord pay?
Answers: 2
question
Computers and Technology, 24.06.2019 08:50
Write a program that will compute the volume of ice cream served in a cone. as you can see in the diagram below, the ice cream is served as a hemisphere of frozen deliciousness on top of a cone, which is also packed with frozen deliciousness. thus, the total volume of ice cream sold is the volume of the hemisphere plus the volume of the cone. the example shows an ice cream cone in which the hemisphere and cone have a radius of 10 inches and the cone has a height of 15 inches. your program must instead prompt for these two values, which are taken from the keyboard as integers: • the hemisphere/cone radius in inches, and
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
Mathematics, 05.12.2020 01:00
question
Mathematics, 05.12.2020 01:00
question
Mathematics, 05.12.2020 01:00
Questions on the website: 13722363