-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBrianReader.java
More file actions
126 lines (111 loc) · 2.43 KB
/
BrianReader.java
File metadata and controls
126 lines (111 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//Brian Pomerantz
import java.io.*;
public class BrianReader {
public BrianReader() {
reader = new InputStreamReader(System.in);
buffer = new BufferedReader(reader);
}
public void pause() {
System.out.print("\nPress Enter to continue . . . ");
try {
buffer.readLine();
}
catch(Exception e) {
//System.exit(0);
}
}
public int readInt(String prompt) {
int value = 0;
String s = "";
while (true) {
System.out.print(prompt);
try {
s = buffer.readLine().trim();
value = (new Integer(s)).intValue();
break;
}
catch(Exception e) {
System.out.println("\n\nError: your input doesn't represent a valid integer value");
pause();
System.out.println();
//System.exit(0);
}
}
return value;
}
public int readInt() {
return readInt("");
}
public double readDouble(String prompt) {
double value = 0.0D;
String s = "";
while (true) {
System.out.print(prompt);
try {
s = buffer.readLine().trim();
value = (new Double(s)).doubleValue();
break;
}
catch(Exception e) {
System.out.println("\n\nError: your input doesn't represent a valid double value");
pause();
System.out.println();
//System.exit(0);
}
}
return value;
}
public double readDouble() {
return readDouble("");
}
public char readChar(String prompt) {
int value = 0;
String s = "";
while (true) {
System.out.print(prompt);
try {
s = buffer.readLine();
s = String.valueOf(String.valueOf(s)).concat("?");
value = s.charAt(0);
break;
}
catch(Exception e) {
System.out.println(String.valueOf(String.valueOf((new StringBuffer("\n\nError in method readChar:\n")).append(e.toString()).append("\n"))));
pause();
//System.exit(0);
}
}
return (char)value;
}
public char readChar() {
return readChar("");
}
public String readLine(String prompt) {
String value = "";
System.out.print(prompt);
try {
value = buffer.readLine();
}
catch(Exception e) {
System.out.println(String.valueOf(String.valueOf((new StringBuffer("\n\nError in Console.readLine\n")).append(e.toString()).append("\n"))));
pause();
//System.exit(0);
}
return value;
}
public String readLine() {
return readLine("");
}
public void cls() {
Clear console = new Clear();
console.cls();
}
private InputStreamReader reader;
private BufferedReader buffer;
}
class Clear {
public native void cls();
static {
System.loadLibrary("clsdll");
}
}