subject

100 POINTS Can you code a working program using these instructions? Note: You MUST be using a computer for this! 1. Create a package (NOT project) named lesson6.
2. Inside lesson6, create a class named DataWriter. This class will contain code that will write data to a file.
3. Inside lesson6, create a class named DataReader. This class will contain code that will read from the file.
4. Add the following import statements to your class. These imported classes will be needed in the code you'll be writing.
import java. io. File;
import java. io. FileNotFoundException;
import java. io. PrintWriter;
5. Create a main() method inside DataWriter. All of the following instructions from 6-9 will be placed inside this method.
6. Create a File object using "data. txt" as the argument to its constructor. Store the reference to the new File object in a variable of type File.
7. Create a PrintWriter object using the reference to the File object you just created as an argument to its constructor. Store the reference to the new PrintWriter object in a variable of type PrintWriter. You might notice that your application will indicate a problem if the code creating a PrintWriter object is not handled by a try-catch block. Supply the appropriate exception handling using either a normal try-catch block or a new try-with-resources statement. Supply a useful error message in the catch block using a System. out. println() statement.
8. Add a System. out. println() statement that displays the text, "Writing to file." This statement will provide visual output so that you can see that the program is actually running.
9. Use the PrintWriter object to write content to the file using print() and println() statements on the PrintWriter object instead of System. out. For example, to write “Hello!” to the file, if your PrintWriter reference is named p, the code would look like this:
p. println("Hello!");
DO NOT actually write “Hello!” to the file. Instead, write a multiplication table. The table should span from 1–10 in rows/columns. For the first row, write code that produce output that looks like this:
1x1=1 1x2=2 1x3=3 1x4=4...
Use a nested loop to loop through rows and columns to produce the desired output. Each element (such as 5x3=15) should be generated using the row number, column number, and their product. The finished output should look like this:
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 1x10=10
...up to
10x1=10 10x2=20 10x3=30 10x4=40 10x5=50 10x6=60 10x7=70 10x8=80 10x9=90 10x10=100
Use nested loops, print(), and println() statements to write this output to the file. Be sure to add spaces between each element as shown above.
Add a System. out. println() statement that displays "Finished writing to file."
Run DataWriter as a Java application. Correct any errors.
If your program ran without errors, it should have created and written to a file named “data. txt”. You can find this file in the root of your project (NOT package). Select the project (above the src directory) and then press the F5 key on your computer. This will refresh the display and you should see the data. txt file at the bottom of the Package Explorer window. Open the file to confirm that it contains the multiplication table shown above.
10. Add the following import statements to DataReader. These imported classes will be needed in the code you will be writing.
import java. io. File;
import java. io. FileNotFoundException;
import java. io. PrintWriter;
11. Create a main() method inside DataReader. All of the following instructions will be placed inside this method.
12. Create a File object using "data. txt" as the argument to its constructor. Store the reference to the new File object in a variable of type File.
13. Display the text "File exists? " (INCLUDING the space after the question mark). On the same line, display the results of the exists() method on the same line as the File object.
14. Create an if-else statement. If the file exists, read the contents of the file (discussed in steps six and seven). If it does not exist, display the text, "Nothing to read. " (INCLUDING the space after the period).
15. Inside the if statement, create a Scanner object using the reference to the File object you just created as an argument to its constructor. Handle the exceptions of the Scanner in a try-catch block or a try-with-resources statement.
16. Use a while loop and the hasNext() and nextLine() methods of the Scanner class to loop through the content of the file and display its contents one line at a time.
17. Run DataWriter as a Java application. If everything works, your output should look like the following.
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 1x10=10
...up to
10x1=10 10x2=20 10x3=30 10x4=40 10x5=50 10x6=60 10x7=70 10x8=80 10x9=90 10x10=100
Thank you!
Note: If you're a Connexus student, please join my class on Quizlet using this link: https: // quizlet. com / join / 6nmuZyd2M (copy-paste into search, then take out ALL spaces)

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:40, Serenitybella
When the pc version of the spreadsheet program became available, the ibm pc quickly became the top-selling personal computer?
Answers: 3
image
Computers and Technology, 22.06.2019 10:30, darrengresham999
Choose the best explanation for the following statement communication is symbolic
Answers: 3
image
Computers and Technology, 22.06.2019 15:10, reycaden
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
image
Computers and Technology, 22.06.2019 17:00, DRock4976
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen too
Answers: 2
You know the right answer?
100 POINTS Can you code a working program using these instructions? Note: You MUST be using a comput...

Questions in other subjects:

Konu
Chemistry, 12.09.2021 04:40