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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 23.06.2019 15:20
In a game with three frames, where will the objects on layer 1 appear? a. next to the play area b. in the middle of the game c. behind everything else d. in front of everything else
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
If an appliance consumes 500 w of power and is left on for 5 hours, how much energy is used over this time period? a. 2.5 kwh b. 25 kwh c. 250 kwh d. 2500 kwh
Answers: 1
question
Computers and Technology, 23.06.2019 21:30
Enzo’s balance sheet for the month of july is shown. enzo’s balance sheet (july 2013) assets liabilities cash $600 credit card $4,000 investments $500 student loan $2,500 house $120,000 mortgage $80,000 car $6,000 car loan $2,000 total $127,100 total $88,500 which expression finds enzo’s net worth?
Answers: 1
You know the right answer?
100 POINTS Can you code a working program using these instructions? Note: You MUST be using a comput...
Questions
question
Mathematics, 17.09.2019 11:30
question
Mathematics, 17.09.2019 11:30
question
Health, 17.09.2019 11:30
question
English, 17.09.2019 11:30
question
Mathematics, 17.09.2019 11:30