Question

1 More Than You Ever Wanted to Know About Pentagons Your assignment here is to create a Pentagon class to represent a regular Pentagon, which has five sides and all angles are of equal length. You will need to create the instance variables, constructors, and instance methods for the Pentagon. 1.1 Instance Methods There is only one thing that distinguishes any regular pentagon from another how big its sides are. Create an instance variable called size to represent the size of the sides. You only need one since they are all the same length. Make size private. If you cannot figure out this very first part do not continue any further with the assignment under any circumstances. Go back and rewatch the lectures or ask for help. 1.2 Constructors We want to set the size of the pentagon when we create it. Create a single constructor for Pentagon, which should take in a double. Use this double to set size of the pentagon. 1.3 Instance Method Complete the following instance methods: 1.3.1 Setters and Getters Create one setter and one getter methodl for the instance variable size 1.3.2 Perimeter Create a method that caleulates and returns the perimeter of the pentagon. 1.3.3 Height Create a method that calculates and returns the height of the pentagon. The pentagons height is the distance fronm once corner to its opposite side
media%2Fa80%2Fa80a0467-10e6-4269-be43-3b
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Explanation:

Below is the Java code for above problem with proper description provided within comments itself. Below code some sample output screenshots are attached.

If you need any other help for this Comment me below. Thanks

Java code :


// class
public class Pentagon {

        // 1.1 instance variable
        private double size;

        // 1.2 constructor
        public Pentagon(double size) {
                super();
                this.size = size;
        }

        // 1.3.1 getter
        public double getSize() {
                return size;
        }

        // and setters
        public void setSize(double size) {
                this.size = size;
        }

        // 1.3.2 calculate parameter
        public double parameter() {
                // calculate parameter
                return 5 * this.getSize();
        }

        // 1.3.3 calculate height
        public double height() {
                // calculate height
                return (Math.sqrt(5 + 2 * Math.sqrt(5)) / 2) * this.size;
        }

        // 1.3.4 calculate width
        public double width() {
                // calculate width
                return ((Math.sqrt(5) + 1) / 2) * this.size;
        }

        // 1.3.5 calculate area
        public double area() {
                // calculate area
                return 0.5 * this.parameter() * this.inradious();
        }

        // 1.3.6 calculate in radius
        public double inradious() {
                // calculate in radius
                return this.size / (2 * Math.tan(Math.PI / 5));
        }

        // 2 testing
        public static void main(String[] args) {
                // create object
                Pentagon p = new Pentagon(5);

                // test the methods
                System.out.println("Height : " + p.height());
                System.out.println("Width : " + p.width());
                System.out.println("Parameter : " + p.parameter());
                System.out.println("Area : " + p.area());
                System.out.println("In Radius : " + p.inradious());
        }
}


Sample Output : 

Problems ConsoleDeclaration Search S Terminal Debug DDisplay <terminated> Pentagon [Java Application] C:\Program FilesJava\jr
Add a comment
Know the answer?
Add Answer to:
1 More Than You Ever Wanted to Know About Pentagons Your assignment here is to create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class...

    ****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • 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, Rectang...

    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...

  • Create a new package in assignment called shapes. All work for this part should be done...

    Create a new package in assignment called shapes. All work for this part should be done in the shapespackage. Create a new interface called Shape. Add double area() and double perimter()methods to the Shape interface. Create two classes called Circle and Rectanglewhich implement Shape. Add reasonable fields to the Circle and Rectangle classes which will allow you to calculate the area and perimeter of each shape. Add constructors to Circle and Rectangle so you can initialize your fields. Implement the...

  • create a java class with the name Brick class: For this part of the assignment, you...

    create a java class with the name Brick class: For this part of the assignment, you will create a class that allows you to specify a colored brick that is capable of drawing itself given a specified Graphics object. Note that this is a regular Java class and does not extend the JApplet class. Your class should a constructor with the following signature: Identifier: Brick(int xPosition, int yPosition, int width, int height, Color color) Parameters: xPosition – an int representing...

  • JAVA Code Requried Copy the file java included below. This program will compile, but, when you...

    JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...

  • Your assignment is to create and test a class for a queue of objects. You may...

    Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue.   The instances of the class should have at least one field that distinguishes each instance from other instances of the class (key property, also called a key field). You should complete the software to implement and test your queue and submit the software along with a project report. Your queue class...

  • You will be creating a driver class and 5 class files for this assignment. The classes...

    You will be creating a driver class and 5 class files for this assignment. The classes are Shape2D (the parent class), Circle, Triangle, and Rectangle (all children of Shape2D) and Square (child of Rectangle). Be sure to include a message to the user explaining the purpose of the program before any other printing to the screen. Within the driver class, please complete the following tasks: Instantiate a Circle object with 1 side and a radius of 4; print it Update...

  • Java programming: please help with the following assignment: Thank you. Create a class called GiftExchange that...

    Java programming: please help with the following assignment: Thank you. Create a class called GiftExchange that simulates drawing a gift at random out of a box. The class is a generic class with a parameter of type T that represents a gift and where T can be a type of any class. The class must include the following An ArrayList instance variable that holds all the gifts,The ArrayList is referred to as theBox. A default constructors that creates the box....

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT