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, 21.06.2019 20:50
What does operator overloading allow you to do?
Answers: 2
question
Computers and Technology, 22.06.2019 23:50
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form.you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used.hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
question
Computers and Technology, 23.06.2019 01:00
Let r be a robotic arm with a fixed base and seven links. the last joint of r is a prismatic joint, the other ones are revolute joints. give a set of parameters that determines a placement of r. what is the dimension of the configuration space resulting from your choice of parameters?
Answers: 3
question
Computers and Technology, 23.06.2019 02:30
How to launch an app: steps to be successful? launching an app is a great idea, but it’s not that easy as we supposed to think. the majority of mobile applications don’t generate revenue because companies aren’t ready to be competitive. referring to our experience in successfully building and launching apps we hope to you omit these difficulties. we are going to talk about ideas, marketing, testing your product, its development, distribution and support. you will learn 8 product launch stages to succeed.
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, 30.01.2020 17:58
question
Mathematics, 30.01.2020 17:58
Questions on the website: 13722363