Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Select the correct answer to the given problem. (1) The following pseudocode rep

ID: 3802424 • Letter: S

Question

  Select the correct answer to the given problem.

(1)       The following pseudocode represents the procedure for reading from a sequential file.

                        open a stream  

                        while more information

                        read information

                        close the stream

            (a)     True        (b)     False

(2)       The try - catch block is designed to enable the programmer to detect and respond        to exception errors.           

            (a)     True        (b)     False

(3)       A sequential file can be sorted by placing its data into an array, sorting the array, and         then writing the ordered data into a file.

            (a)     True        (b)     False

(4)       A control break is a temporary break from the flow of the logic of a program.

            (a)     True        (b)     False

(5)       Opening a file for output means that __________ .

            (a)     data may be stored onto the disk.

            (b)     data may be read from the disk.

            (c)     anything that appears as output on the screen is written to the disk.

(d)     data may be read from and stored onto the disk.

(6)       When a file is opened in the append mode, data written to the file replaces the data            already there.   

            (a)     True        (b)     False

(7)       Which of the following statements is used when you want to add data to the end of an         existing sequential file?

            (a)     FileWriter in = new FileWriter(outputFile);

            (b)     FileReader in = new FileWriter(outputFile, true);

            (c)     FileReader out = new FileWriter(outputFile);

            (d)     FileWriter out = new FileWriter(outputFile, true);

(8)       When an existing file is opened for output, and not append, new data values are added at the end of the existing file.

            (a)     True        (b)     False

(9)       If a sequential file is opened for input, then this allows data to be placed into the file by the Java application.

            (a)     True        (b)     False

(10)     Which of the terms in the following line of code are named variables that could be replaced as long as all other references were also updated?

                        FileReader in = new FileReader(inFile);

            (a) inFile     (b) in              (c) new                 (d) File          (e) FileReader

Considering the following class file, answer each of the questions given below.

import java.io.*; import java.io.FileReader;

import java.io.FileWriter;

public class ReadWrite {

public static void main(String[] args) throws IOException {

   

    File inputFile = new File("inData.txt");

    File outputFile = new File("outData.txt");

    FileReader in = new FileReader(inputFile);

    FileWriter out = new FileWriter(outputFile, true);

    int c;

    while ((c = in.read()) != -1)

      out.write(c);

    in.close();

    out.close();

}

     }

(11)     in is a FileWriter object.                                                   (a) True (b) False

(12)     out is a FileReader object.                                                 (a) True (b) False

(13)     inputFile is a File object associated with outData.txt . (a) True (b) False

(14)     outputFile is a File object linked with inData.txt .      (a) True (b) False

(15)     out.close() is outside the block of the while loop.             (a) True (b) False

(16)     in.close() is inside the block of the while loop.                  (a) True (b) False

(17)     The while loop is used to both read from and write to the file.    (a) True (b) False

(18)     (c = in.read()) != -1 is true when data can still be read.   (a) True (b) False

import java.io.*; import java.io.FileReader;

import java.io.FileWriter;

public class ReadWrite {

public static void main(String[] args) throws IOException {

   

    File inputFile = new File("inData.txt");

    File outputFile = new File("outData.txt");

    FileReader in = new FileReader(inputFile);

    FileWriter out = new FileWriter(outputFile, true);

    int c;

    while ((c = in.read()) != -1)

      out.write(c);

    in.close();

    out.close();

}

     }

Explanation / Answer

Hi, I have provided the anser till question- 10. To get answers to othe question, please repost the ques and i will answer.

1)The following pseudocode represents the procedure for reading from a sequential file.

open a stream
while more information
read information
close the stream
Ans- (a) True
Explaination:-The The following example shows how to read lines from a file and print these to the standard output stream. It reads its own source file, which must be in the current directory.
// Demonstrate FileReader.
import java.io.*;
class FileReaderDemo {
public static void main(String args[]) throws Exception {
FileReader fr = new FileReader("FileReaderDemo.java");
BufferedReader br = new BufferedReader(fr);
String s;
while((s = br.readLine()) != null) {
System.out.println(s);
}
fr.close();
}
}

2)The try - catch block is designed to enable the programmer to detect and respond to exception errors.
Ans- (a) True
Explaination:-ava try block is used to enclose the code that might throw an exception. It must be used within the method.
Java try block must be followed by either catch or finally block.

3)A sequential file can be sorted by placing its data into an array, sorting the array, and then writing the ordered data into a file.
Ans- (a) True

4)A control break is a temporary break from the flow of the logic of a program.
Ans- (a) True
Explaination:-a control break is a temporary detour in the logic of a program. programmers refer to a program as a control break program when a change in the value of a variable initiates special actions or causes special or unusual processing to occur.

5)Opening a file for output means that
Ans- (a) data may be stored onto the disk.

6)When a file is opened in the append mode, data written to the file replaces the data already there.   
Ans- (b) False
Explaination:- data written to the file are added at the end of the file.

7)Which of the following statements is used when you want to add data to the end of an existing sequential file?
Ans-d) FileWriter out = new FileWriter(outputFile, true);
Explaination:-When constructing a FileWriter with given a File object, if the second argument is true, then bytes will be written to the end of the file not the beginning.


8)When an existing file is opened for output, and not append, new data values are added at the end of the existing file.
Ans- (b) False
Explaination:-the file is erased completely and new data are added at the beginning of the file.

9)If a sequential file is opened for input, then this allows data to be placed into the file by the Java application.
Ans-(b) False
Explaination:-data that is in the file to be used in the Visual Basic application

10)Which of the terms in the following line of code are named variables that could be replaced as long as all other references were also updated?

FileReader in = new FileReader(inFile);
Ans- (b) in
Explaination:- new , File ,FileReader are keywords. inFileis the file name.Hence in is the variable that can be changed.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote