Java: Use BufferedReader not Scanner • public void display( String str ) — This
ID: 3871951 • Letter: J
Question
Java:
Use BufferedReader not Scanner
• public void display( String str ) — This method will display the value of str to the screen. You will need to use System.out.print() rather than System.out.println() here.
• public String getInput() — This method will get input from the user and return what the user enters as a String.
• public void pause( String message ) — This method will print the incoming message and wait for the user to press the ENTER/RETURN key.
public void clearScreen() — This method will print 25 blank lines to the screen.
1. The user interface will adapt its spacing to that of a standard character terminal (25 lines x 80 columns).
2. In all cases where the user is asked to enter information following a prompt, the user’s input must be on the same line as the prompt (and not on the line below).
3. When the program begins, the following screen will display:
Bibliography Manager
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
(A)dd, (E)dit, (D)elete, (S)earch, read(L)ist, (N)ext, (B)ack, (Q)uit
Choose Operation ->
**************************************************************************************************
4. The first two lines will be centered at the top of the screen. These will then be followed by 2 blank lines. The next 16 lines should be numbered from 1 to 16 as shown above (all should be followed by a period, and the periods should be vertically aligned). This will be followed by another blank line followed by list of the possible operations that can be performed. This list of operations should be centered. Note: parentheses are used to designate the letter to be used to perform a particular operation. This, in turn, is followed by another blank line which is followed by the user’s prompt (“Choose Operation”). The user’s prompt should be aligned with the list of operations above. Make sure to include a single space following the prompt (“-> ”) so that the user entry does not abut against the prompt.
5. The user must choose one of the letters enclosed by parenthesis in the screen above. If the user enters an incorrect value, the program should print an error message along with the incorrect entry and force the user to re-enter the value. For example, if the user enters the number “3” instead of one of the allowable choices, the output will appear like this:
Incorrect entry (3). Please re-enter.
Choose operation ->
This error message and re-prompt should continue to appear so long as the user persists in entering incorrect data. Both the error message and the re-prompt should be aligned with the list of operations and the prompt above.
If the user chooses “E” or “e” (for “Edit”), the program should print 25 blank lines to the screen (to clear the original screen) and then print the following:
Edit Book
This function is not currently available. Press <ENTER> to continue . . .
Once the user presses the key, the program the program should print 25 blank lines to the screen (to clear the original screen) and return to the opening screen.
Explanation / Answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Driver {
public void display(String str) {
System.out.print(str);
}
public String getInput() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
System.out.print("Enter your input ");
String input = reader.readLine();
System.out.println("Your input is: " + input);
return input;
}
public void pause(String message) {
System.out.println("the message is " + message);
}
public void clearScreen() {
for (int i = 0; i < 25; i++) {
System.out.println(i + ".");
}
}
public static void main(String[] args) throws IOException {
Driver driver=new Driver();
driver.clearScreen();
driver.display("this is a demo program");
driver.pause("this is a demo program");
driver.getInput();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.