Java Reference
In-Depth Information
jminusminus.Parser
Employee
Exercise 1.21. Write the method descriptor for each of the following constructors/method
declarations:
publicEmployee(Stringname)...
publicCoordinates(floatlatitude,floatlongitude)...
publicObjectget(Stringkey)...
publicvoidput(Stringkey,Objecto)...
publicstaticint[]sort(int[]n,booleanascending)...
publicint[][]transpose(int[][]matrix)...
Exercise 1.22. Write a program (Appendix A describes how this can be done)
GenGCD.
java
that produces, using
CLEmitter
, a
GCD.class
file with the following methods:
//ReturnstheGreatestCommonDivisor(GCD)ofaandb.
publicstaticintcompute(inta,intb){
...
}
Running
GCD
as follows:
>javaGCD4284
should output
>42
Modify
GenGCD.java
to handle
java.lang.NumberFormatException
that
Integer.
parseInt()
raises if the argument is not an integer, and in the handler, print an appropriate
error message to
STDERR
.
Exercise 1.23. Write a program
GenPrimality.java
that produces, using
CLEmitter
,
Primality.class
,
Primality1.class
,
Primality2.class
, and
Primality3.class
les,
where
Primality.class
is an interface with the following method:
//Returnstrueifthespecifiednumberisprime,false
//otherwise.
publicbooleanisPrime(intn);
and
Primality1.class
,
Primality2.class
, and
Primality3.class
are three different
implementations of the interface. Write a j-- program
TestPrimality.java
that has a test
driver for the three implementations.
Exercise 1.24. Write a program
GenWC.java
that produces, using
CLEmitter
, a
WC.class
which emulates the UNIX command
wc
that displays the number of lines, words, and bytes
contained in each input file.
Exercise 1.25. Write a program
GenGravity.java
that produces, using
CLEmitter
, a
Gravity.class
file which computes the acceleration g due to gravity at a point on the
surface of a massive body. The program should accept the mass M of the body, and the
distance r of the point from body's center as input. Use the following formula for computing
g:
Search WWH ::
Custom Search