Java Reference
In-Depth Information
public
public class
SimpleCalcScanner
{
/** The Scanner */
protected
class
SimpleCalcScanner
protected
Scanner scan
;
/** The output */
protected
protected
PrintWriter out
=
new
new
PrintWriter
(
System
.
out
);
/** The variable name (not used in this version) */
protected
protected
String variable
;
/** The operand stack; no operators are pushed, so it can be a stack of Double */
protected
protected
Stack
<
Double
>
s
=
new
new
Stack
<>();
/* Driver - main program */
public
public static
static
void
void
main
(
String
[]
args
)
throws
throws
IOException
{
iif
(
args
.
length
==
0
)
new
new
SimpleCalcScanner
(
new
new
InputStreamReader
(
System
.
in
)).
doCalc
();
else
else
for
(
String arg
:
args
) {
new
new
SimpleCalcScanner
(
arg
).
doCalc
();
}
}
/** Construct a SimpleCalcScanner by name */
public
public
SimpleCalcScanner
(
String fileName
)
throws
throws
IOException
{
this
this
(
new
new
FileReader
(
fileName
));
}
/** Construct a SimpleCalcScanner from an open Reader */
public
public
SimpleCalcScanner
(
Reader rdr
)
throws
throws
IOException
{
scan
=
new
new
Scanner
(
rdr
);
}
/** Construct a SimpleCalcScanner from a Reader and a PrintWriter */
public
public
SimpleCalcScanner
(
Reader rdr
,
PrintWriter pw
)
throws
throws
IOException
{
this
this
(
rdr
);
setWriter
(
pw
);
}
/** Change the output to go to a new PrintWriter */
public
public
void
void
setWriter
(
PrintWriter pw
) {
out
=
pw
;
}
protected
protected
void
void
doCalc
()
throws
throws
IOException
{