150
Programming Problems
1.Java systems provide a set of user-defined types that duplicate the names of
primitive types except that the first letter of the type name is capitalized (for ex-
ample,Doubleand Longinstead of doubleand long). The one exception is that the
type corresponding to intis called Integer. Each of these types contains declara-
tions of constants related to the corresponding primitive type. Two of these con-
stants are Integer.MAX_VALUEand Integer.MIN_VALUE, the largest and smallest int
values that Java allows. Write an application to display the values of
Integer.MAX_VALUEand Integer.MIN_VALUE. The output should identify which value
is Integer.MAX_VALUEand which value is Integer.MIN_VALUE. Be sure to include ap-
propriate comments in your code, and use indentation as we do in the code in
this chapter. Each of these types defines similar constants, so you may want to
extend your application to display Long.MIN_VALUE, and so on, just to learn what
the actual maximum and minimum numbers are for each of the primitive types.
2.Write an application that outputs three lines as follows:
7 / 4 using integer division equals <result>
7 / 4 using floating-point division equals <result>
7 modulo 4 equals <result>
where <result>stands for the result computed by your application. Use named
constants for 7 and 4 everywhere in your application (including the output state-
ments) to make the application easy to modify. Be sure to include appropriate
comments in your code, choose meaningful identifiers, and use indentation as
we do in the code in this chapter.
3.Write a Java application that takes an integral Celsius temperature as input and
converts it to its Fahrenheit equivalent. The formula is
Fahrenheit = Celsius + 32
After the Celsius temperature is input, it should be displayed along with the cor-
responding Fahrenheit equivalent. The application should include appropriate
messages identifying each value. Be sure to include appropriate comments in
your code, choose meaningful identifiers, and use indentation as we do in the
code in this chapter.
4.Write an application to calculate the diameter, circumference, and area of a cir-
cle with a radius input by the user. Assign the radius to a floatvariable, and then
output the radius with an appropriate message. Declare a named constant PI
with the value 3.14159. The application should output the diameter,
circumference, and area, each on a separate line, with identifying labels. Be sure
to include appropriate comments in your code, choose meaningful identifiers,
and use indentation as we do in the code in this chapter.
^9
5
T
E
A
M
F
L
Y
Team-Fly®