Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fall 2017 CS163: Java Programming The purpose of this lab is to: Learn the basics of file input/output (I/O) Learn how to read a file

Fall 2017

CS163: Java Programming The purpose of this lab is to:

Learn the basics of file input/output (I/O)

Learn how to read a file using Scanner

Learn how to write a file using PrintWriter

Java Programming

Phase 1

Make a new project and class in Eclipse called R16, with a main method. Download the data file from here. Set up the Run Configuration so that R16 has the program arguments: input.txt output.txt This is the same as reading command line arguments from the terminal. Create two methods with the following signatures: public void readFile( String inputFile ){ } public void writeFile( String outputFile ){ } Within the main method, call the readFile method with the first command line argument (args[0]), then call the writeFile method with the second command line argument (args[1]).

Phase 2

Implement the readFile method to open the input file, print the type of the next token (string separated by white space or punctuation) and the token itself, as shown below. Your code should read tokens until the end of the file is reached, and it should close the file when finished. Handle the data types integer, double, and string. Exceptions should be handled as shown in class and in the recitation. Make sure your program successfully reads the input values and prints them. Remember that some types can be upgraded from a lower type to higher type. The output from the provided file (input.txt) should exactly match the following:

String: And String: you String: feel String: that String: you String: have String: exerted String: your String: very String: best String: efforts String: in String: the String: matter, String: do String: you? String: That String: you String: have String: exercised String: all String: of String: your String: considerable String: ingenuity? String: Albus String: Dumbledore String: to String: Harry String: Potter Integer: 1 Double: 0.1 String: @ Integer: 12 Double: 0.123 String: $ Integer: 123 Double: 0.1234 String: % Integer: 1234 Double: 0.12345 String: ^ Integer: 12345 String: & String: FALSE String: TRUE String: Computer String: Science Integer: 13579 String: ~ Double: 999.98 String: Whatever String: A String: B String: C 

Phase 3

Implement the writeFile method to open the output file, prompt the user with "Enter text:", then read input from the user via the keyboard, print the input to the file, and close the output file. When the user types stop (uppercase or lowercase) by itself on its own line, the method should terminate. Given this input from the console: Enter text: Hello! Here are some words. stop can be written here, but it still makes it in. so will this stop. stop! stop The output file should exactly match the following: Hello! Here are some words. stop can be written here, but it still makes it in. so will this stop. stop!

here

And you feel that you have exerted your very best efforts in the matter, do you? That you have exercised all of your considerable ingenuity? Albus Dumbledore to Harry Potter 1 0.1 @ 12 0.123 $ 123 0.1234 % 1234 0.12345 ^ 12345 & FALSE TRUE Computer Science 13579 ~ 999.98 Whatever A B C 

Input.txt

And you feel that you have exerted your very best efforts in the matter, do you? That you have exercised all of your considerable ingenuity? Albus Dumbledore to Harry Potter 1 0.1 @ 12 0.123 $ 123 0.1234 % 1234 0.12345 ^ 12345 & FALSE TRUE Computer Science 13579 ~ 999.98 Whatever A B C 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

a. Do team members trust each other?

Answered: 1 week ago