Question: Write the java programming (3 program following). 1. ( Computing x ) Approximate the value of a quantity x using the following series: x =
Write the java programming (3 program following).
1. (Computing x) Approximate the value of a quantity x using the following series:
x = 1 + 1/2 + 1/3 + 1/4+....+1/n where n is a positive integer. The value of n should be passed to the method.
Write a java method that calculates and displays the value of x for n (for example n = 1000).
2. (Area of 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 where n is the number of sides and s is the side of the polygon.
Write a Java method that returns the area of a regular polygon using the following header:
public static double area(int n, double side).
(Hints: You may need Math.tan() function and Math.PI for area calculations.)
3. (Rectangle class) Design a class to represent a rectangle. The class is specified as follows:
(i) Two double data fields named width and height hold the width and height of the rectangle. The default values are 1 for both width and height.
(ii) A no-arg constructor creates a default rectangle.
(iii) Getter and setter methods are provided for all data fields.
(iv) Accessor methods return the area and the perimeter.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
