Computers and Technology

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)

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:40, bartekpiglo
Write an assembly program with the following specifications. a). in the main block, you should have two registers r4 and r5. they should be checked in an infinite loop. if r4 is greater than r5, then the greater subroutine will be called. if r4 is less than r5, then the less subroutine will be called. if r4 equals r5, then no operations will be done
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, Siris420
Plz ( which is an example of a good url?
Answers: 1
image
Computers and Technology, 24.06.2019 03:30, laylay120
Other - a written response, no less than arial 12-point font, to the following: of the following, which would you consider is most important to customer service goals? choose one and explain why. (1) accuracy (2) punctuality and attendance (3) courtesy (4) productivity (5) organization
Answers: 1
image
Computers and Technology, 24.06.2019 13:00, ddaaaeeee2960
Which one of the following functions is not available on the autosum tool? sum average if max
Answers: 3
Do you know the correct answer?
100 POINTS Can you code a working program using these instructions? Note: You MUST be using a comput...

Questions in other subjects:

Konu
Mathematics, 14.07.2019 02:00
Konu
Mathematics, 14.07.2019 02:00