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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:00, yentel110306
When building customer relationships through email what should you not do? question 2 options: utilize proper grammar, spelling, and punctuation type in all capital letters use hyperlinks rather than attachments respond to all emails within 24 hours
Answers: 1
image
Computers and Technology, 23.06.2019 21:40, jeovontamarley
language consists of basic components, and they are called a. 3; mental images, concepts, and speech b. 2; language acquisition and linguistic relativity c. 3; heuristics, algorithms, and analogies d. 4; phonemes, morphemes, syntax, and semantics e. 2; words and grammar
Answers: 3
image
Computers and Technology, 23.06.2019 22:20, Izzyfizzy
Read “suburban homes construction project” at the end of chapters 8 and 9 (in the textbook) and then develop a wbs (work breakdown structure) in microsoft excel or in microsoft word (using tables)
Answers: 1
image
Computers and Technology, 24.06.2019 07:20, stephanieyingepbtcf8
3pointsyou've found an image you want to insert into your slide presentation. youwant to make the image look more gray so that it looks like an older imagewhat would you need to adjust? 0.00o a. sizeo b. hueo c. contrasto d. tones
Answers: 2
You know the right answer?
"console/file input and output" text file
for this assignment, you will build on "starter" co...

Questions in other subjects:

Konu
Mathematics, 11.07.2019 16:00
Konu
Mathematics, 11.07.2019 16:00