Java Reference
In-Depth Information
**6.34
( Print calendar ) Programming Exercise 3.21 uses Zeller's congruence to calcu-
late the day of the week. Simplify Listing 6.12, PrintCalendar.java, using Zeller's
algorithm to get the start day of the month.
6.35
( Geometry: area of a pentagon ) The area of a pentagon can be computed using the
following formula:
s 2
5
*
Area
=
5
4
*
tan
¢
Write a method that returns the area of a pentagon using the following header:
public static double area( double side)
Write a main method that prompts the user to enter the side of a pentagon and
displays its area. Here is a sample run:
Enter the side: 5.5
The area of the pentagon is 52.04444136781625
*6.36
( Geometry: area of a regular polygon ) A regular polygon is an n -sided polygon
in which all sides are of the same length and all angles have the same degree (i.e.,
the polygon is both equilateral and equiangular). The formula for computing the
area of a regular polygon is
s 2
n
*
Area
=
n
4
*
tan
¢
Write a method that returns the area of a regular polygon using the following header:
public static double area( int n, double side)
Write a main method that prompts the user to enter the number of sides and the
side of a regular polygon and displays its area. Here is a sample run:
Enter the number of sides: 5
Enter the side: 6.5
The area of the polygon is 72.69017017488385
6.37
( Format an integer ) Write a method with the following header to format the inte-
ger with the specified width.
public static String format( int number, int width)
The method returns a string for the number with one or more prefix 0 s. The size
of the string is the width. For example, format(34, 4) returns 0034 and for-
mat(34, 5) returns 00034 . If the number is longer than the width, the method
 
Search WWH ::




Custom Search