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 15:30
In a compound condition, both conditions on either side of the logical operator and must be true for the overall condition to be true. a: true b: false
Answers: 1
question
Computers and Technology, 22.06.2019 17:40
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i.e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
question
Computers and Technology, 23.06.2019 01:20
Write a function balancechemical to balance chemical reactions by solving a linear set of equations. the inputs arguments are: reagents: symbols of reagents in string row array products: symbols of products in string row array elements: elements in the reaction in string row array elcmpreag: elemental composition of reactants in two dimensional numeric array elcmpprdcts: elemental composition of prducts in two dimensional numeric array hint: the first part of the problem is setting up the set of linear equations that should be solve. the second part of the problem is to find the integers from the solution. one way to do this is to mulitiply the rational basis for the nullspace by increasing larger integers until both the left-and right-side integers exist. for example, for the reaction that involves reacting with to produce and : reagents=["ch4", "o2"]; products =["co2", "h2o"]; elements =["c","h", "o"] elcmpreag=[1,4,0;
Answers: 3
question
Computers and Technology, 23.06.2019 04:00
Another name for addicting games.com
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, 26.08.2021 22:20
question
Mathematics, 26.08.2021 22:20
question
Mathematics, 26.08.2021 22:20
Questions on the website: 13722363