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

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

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

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

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

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

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

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

  • (JAVA) Programming Assignment 3 There are a number of zoos available to tourists. 1. Create a...

    (JAVA) Programming Assignment 3 There are a number of zoos available to tourists. 1. Create a Zoo class. Include data fields such as name of zoo, location, size, fee for the past 12 months, number of visitors recorded for the past 12 months, admission rates per visitor and annual budget. (20 points) 2. Include at least two mutators and two accessors. (15 points) 3. Include one default constructor and one more constructor. (15 points) 4. Write separate instance methods that...

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

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
ADVERTISEMENT