Describe in sentences, what is happening in the area highlighted in yellow? [NOT
ID: 3717991 • Letter: D
Question
Describe in sentences, what is happening in the area highlighted in yellow? [NOTE: You need to explain why certain methods are being over ridden].
import javax swing.*; public class Console public static String readLine (_ StringBuilder response = new StringBuilder(): Try f BufferedInputStream binnew BufferedInputStream( System.out); int in0 char inChar; Do 1 in = bin . read ( ); inChar-(char) in; response.append(inChar); 1 While ((in! -1) & (inChar!- 'In')); bin,close (); return re s pon s e.tostring) > Catch (IOexception e) System.out .println( "Exception: "e. get Message)) return nulExplanation / Answer
import javax.swing.*;
import java.io.BufferedInputStream;
import java.io.IOException;
public class Console{
public static String readLine() {
StringBuilder response = new StringBuilder(); //This line create StringBuilder Object to build response string.
try {// Start try-catch block
//BufferedInputStream bin = new BufferedInputStream(System.out);
//This is wrong way to create BufferedInputStream.
//Below way is correct to create Obj.
//This line is used to create BufferedInputStream Object to read input from console.
BufferedInputStream bin = new BufferedInputStream(System.in);
int in = 0;
char inChar;
do { //Starting do-while loop to take input from console.
in = bin.read(); // Reading input from console
inChar = (char) in; //Type Cast integer to char.
if(in != -1) { //Checking Console input is -1 or not
response.append(inChar); //Appending input character to response string
}
} while(in != -1 & (inChar != ' ')); //Stopping do-while loop when input character is new line.
bin.close(); //Closing input stream.
return response.toString(); //Returning response string
} catch(IOException e) { //Catching IOException
System.out.println("Exception: " + e.getMessage()); //Printing exception while reading from console
return null; // Return null
}
}
}