I just need help on number 7a, 7b, and 8, Thank you! What does each of the follo
ID: 3830645 • Letter: I
Question
I just need help on number 7a, 7b, and 8, Thank you!
What does each of the following do? a. import java.io File; b. import java io.PrintWriter; c. File myFile = new File("data.txt"); creates a File object using a constructor that includes argument, d. if (myFile.exists()){.exists checks to see if myFile exists or not by e. System out print("Replace file data.txt? (y or n): char reply = keyboard.next().toLowerCase().char Asks user to replace data.txt by typing y or n, typing in the character. f. if (reply ! = 'y') if the reply is not 'y' g. System.exit(0);} Program turns off What does each of the following do? a. PrintWriter myWriter = new PrintWriter(myFile); b. my Writer print (courseName + ""); c. my Writer.println(numberOfStudents); d. my Writer, close(); What does each of the following do? a. Scanner myScanner = new Scanner(myFile); Create a Scanner for the file b. while (myScanner.has MNext()) Read data from a fileExplanation / Answer
Question 7a.
Answer: Importing File class into the current class
Question 7b
Answer: Importing the PrintWriter class into curren class
Question 8
Answer:
in line 1, we are creating printwriter object by passing file object as an arguement.
in line2, we are writing Coursename into file with no new line
in line 3, we are writing number of students into file with new lline
in line4, we are closing the file stream. means printWriter object.