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](//img.homeworklib.com/questions/fda316c0-0188-11ec-a76a-91e40c5f4445.png?x-oss-process=image/resize,w_560)
1 More Than You Ever Wanted to Know About Pentagons Your assignment here is to create...
****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 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, 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 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 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 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 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 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 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 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...