UML class diagram
//program in java
import java.lang.*;
//--------------------------
class RegularPolygon{
private int n;
private double side;
private double x;
private double y;
//default constructor
public RegularPolygon(){
n=3;
side=1;
x=y=0;
}
//parameterized constructor
public RegularPolygon(int m,double len){
n=m;
side=len;
x=y=0;
}
//parameterized constructor
public RegularPolygon(int m,double len,double a,double
b){
n=m;
side=len;
x=a;
y=b;
}
public void setNumberOfSide(int m){
n=m;
}
public void setSideLength(double len){
side=len;
}
public void setXcoordinate(double a){
x=a;
}
public void setYcoordinate(double b){
y=b;
}
public int getNumberOfSide(){
return n;
}
public double getSideLength(){
return side;
}
public double getXcoordinate(){
return x;
}
public double getYcoordinate(){
return y;
}
//finds perimeter
public double getPerimeter(){
return n*side;
}
//find area
public double getArea(){
double
area=(n*side*side)/(Math.tan(Math.PI/n)*4);
return area;
}
}
//----------main class-------------
public class RegularPolygonMain{
public static void main(String args[]){
RegularPolygon p1=new
RegularPolygon();
RegularPolygon p2=new
RegularPolygon(6,4);
RegularPolygon p3=new
RegularPolygon(10,4,5.6,7.8);
System.out.println("perimeter=
"+p1.getPerimeter());
System.out.println("Area=
"+p1.getArea());
System.out.println("perimeter=
"+p2.getPerimeter());
System.out.println("Area=
"+p2.getArea());
System.out.println("perimeter=
"+p3.getPerimeter());
System.out.println("Area=
"+p3.getArea());
}
}
//------------------------
ouput:
Problem 2 9.9 Geometry: n-sided regular polygon pg. 362 (25 points) Follow instructions as provided on...
//include comments
Opts (Regular polygon) An n-sided regular polygon has n sides of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: Aprivate int data field named n that defines the number of sides in the polygon with default value 3. A private double data field named side that stores the length of the side with default value 1. A private double data field...
(Geometry: n-sided regular polygon) An n-sided regular polygon’s sides all have the same length and all of its angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: ■ A private int data field named n that defines the number of sides in the polygon. ■ A private float data field named side that stores the length of the side. ■ A private float data field named x that defines...
N-Sided Polygon An n-sided polygon is a planed figure whose sides have the same length and whose angles have the same degree. Write a class called NSidedPolygon that contains the following components: Private members to store the name of a polygon, the number of sides, and the length of each side. (You are expected to select the appropriate data types for each member.) A constructor that accepts the number of sides and the length of each side. A private method...
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 isArea =Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area. Here is a sample run:
Write a simple class representing a Polygon up to 6 sides: the Polygon class has 5 fields: Regular, sides, sideLength, angle, apothem Polygon: Regular: boolean sides: int sideLength: double angle : double apothem : double Provide a no-arg constructor for this class initializes the object and sets the instance variables to: Regular: true sides: 3 sideLength: 1 angle : 60 apothem : SquareRoot(3)/2 Provide the following methods: Set number of sides set the length of the sides set the angle...
Please include comments in the program .The program must be able to be compiled.Design a class named Triangle that extends GeometricObject. This class contains:* Three double data fields named side1, side2, and side3 with default values 1.0 to denote the three sides of a triangle.* A no-arg constructor that creates a default triangle.* A constructor that creates a triangle with the specified side1, side2, and side3.* The accessor methods for all three data fields.* A method named getArea() that returns...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Language is JAVA.
Clarification for the Shape class (highlighted):
The following requirements specify what fields you are expected
to implement in your Shape class;
- A private String color that specifies the color of the
shape
- A private boolean filled that specifies whether the shape is
filled
- A private date (java.util.date) field dateCreated that
specifies the date the shape was created Your Shape class will
provide the following constructors;
- A two-arg constructor that creates a shape
with...
Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle with color = "blue", filled = true. A constructor that creates a triangle with the specified side1, side2, side3 and color = "blue", filled = true. The accessor functions for all three data fields, named getSide1(), getSide2(), getSide3(). A function...
Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...