subject

"console/file input and output" text file
for this assignment, you will build on "starter" code to create a java™ program that prompts the user for input, accepts user input, and produces both console and file output.
copy the linked code to a java file.
add java® code based on the comments inside the code.
note: refer to this week's individual "week two analyze assignment" for model code you can adapt to meet this assignment's requirements.
test, debug, and run your code using the netbeans editor to make sure it meets the program requirements.
here is the code given with the comments of instruction included:
/
* program: week 2 code assignment
* purpose: console/file input and output
* programmer: your name here
* class: prg/421r13, java programming ii
* instructor: your instructor here
* creation date: today's date
* comments: fill in code
*
/
package demo;
import java. util. scanner; // scanner is a predefined class for taking inputs from user
public class startercode
{
public static void main(string[] args)
{
// prompts and accepts user input
scanner input= new scanner(system. in);
double data;
system. out. println("enter value ");
// accepts file input
string filename = "input. txt"; // name of the file to open
string line = null; // will reference one line at a time
try {
filereader filereader = // filereader reads text file
new filereader(filename); // reads in data from the file
// produces both console and file output
try { // coding block to output data to file
filestdout = new printstream(new fileoutputstream("data. txt")); // output file name is data. txt
system. out. println(""); // output to console, numbers 0 through 9
filestdout. println("" + i);
// enter your code here. enter code to end program successfully.
this is the analyze assignment that we are to reference for model code we can adapt to meet this assignment's requirements.
/
* program: fileout
* purpose: demonstrate the coding to produce output to a file.
* programmer: i am student
* class: prg/421r13, java programming ii
* instructor:
* creation date: 01/03/2018
*
/
package fileout;
import java. io.*;
public class fileout {
public static void main(string[] args) {
inputstream istream;
outputstream ostream=null;
// fileoutputstream creates an outputstream that you can use to write bytes to a file.
int c; // character stream
final int eof = -1; // eof indicator
istream = system. in;
// if the data. txt file already exists, present its contents on the console.
string filename = "data. txt"; // name of the file to open.
string line = null; // will reference one line at a time
try {
filereader filereader = // filereader reads text file
new filereader(filename); // reads in data from the file
// always wrap filereader in bufferedreader (to verify)
bufferedreader bufferedreader =
new bufferedreader(filereader);
system. out. println("here are the contents of the current file named " + filename + ": \n");
while((line = bufferedreader. = null) {
system. out. println(line); // verify / display what is read in by the program
}
bufferedreader. close(); // close file
}
catch(filenotfoundexception ex) { // coding to verify file can be opened
system. out. println( // if not open, error message to display
"unable to open file '" +
filename + "'");
}
catch(ioexception ex) { // exception, when there is an error in reading
system. out. println(
"error reading file '"
+ filename + "'");
}
// now, let's construct a new file containing user input.
system. out. println("\ntype characters to write to file. after you finish, press ctrl+shift+del to end.");
file outfile = new file("data. txt"); // create a new file
try { // try block for eof indicator
ostream = new fileoutputstream(outfile);
while ((c = istream. = eof) // look for end of file in istream
ostream. write(c);
} catch (ioexception e) {
system. out. println("error: " + e.;
} finally {
try { // try block for file error ñ file did not close
istream. close(); // close input and output
ostream. close();
} catch (ioexception e) {
system. out. println("file did not close");
}
}
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 04:30
Which of the statements below is true? the formatting, standard, and drawing commands are unavailable. the formatting, standard, and drawing commands have been used. the formatting, standard, and drawing toolbars are displayed. the formatting, standard, and drawing toolbars are hidden.
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
When is a chart legend used a. all the time b. whenever you are comparing data that is the same c. whenever you are comparing multiple sets of data d. only for hand-drawn charts
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
To check spelling errors in a document, the word application uses the to determine appropriate spelling. internet built-in dictionary user-defined words other text in the document
Answers: 2
question
Computers and Technology, 23.06.2019 18:00
Freya realizes she does not have enough in her bank account to use the debit card. she decides to use a credit card instead. which questions should freya answer before using a credit card? check all that apply. can i pay at least the minimum payment each month? can i make payments on time and avoid late fees? will i have to take out a loan? how much in finance charges can i afford to pay? should i talk to a consumer credit counseling service?
Answers: 1
You know the right answer?
"console/file input and output" text file
for this assignment, you will build on "starter" co...
Questions
question
Mathematics, 18.10.2020 15:01
question
English, 18.10.2020 15:01
Questions on the website: 13722359