Question
N-Sided Regular Polygon General Rules for Homework Assignments: The beginning comment section must have at a minimum the following or points will be deducted: o
N-Sided Regular Polygon
General Rules for Homework Assignments:
- The beginning comment section must have at a minimum the following or points will be deducted: o The name of the developer and the date written o The instructors name o The course and section number o A statement as to its purpose o The inputs and outputs o A list of exposed interfaces
o A list of all variables, their type, and their purpose
- You are strongly encouraged to add comments throughout the program. Doing so will help your instructor to understand your programming logic and grade you more accurately.
- You must work on your assignments individually. You are not allowed to copy any code, in whole or part, from the others. However, you may discuss approaches to the homework assignment with your section mates and the instructor.
- Each assignment has a strict deadline. Due dates are posted on the Schedule. Remember that ALL assignments must be completed to pass this course.
- When the term YourName is referenced in an assignment, please replace it with your name.
Assignment:
Create a new Java Project named YourNameAssignment2 and complete the following requirements. Write a program that displays a regular polygon and uses two buttons named +1 and -1 to increase or decrease the size of the polygon, as shown in the following figure.
To receive full credit your program will need to meet the following specifications:
- Create the UI that looks like the example dialogs.
- Your program should correctly display an n-sided polygon.
- Your program should handle action events from the buttons.
- Your program should redisplay the polygon when the user clicks the buttons.
- Your program should allow for the changing of the interior color of the polygon.
Example Dialogs:
What you will need in for the code:
Your java code will have three sections:
- The YourNameAssignment1 class which will be an extension of the Application class
- The start method will be located here
- The panes width and height will be set to 270 x 210
- An instance of the polygon class (see item 3 below) is created with a default of 6 sides
- The polygon instance is set in the center of the BorderPane
- The bindings to the polygon classs methods to increase and decrease the number of sides will be located here
- The BorderPane, HBox and Scene will be instantiated here
- The states title is set
- The + and buttons are created and located in the HBox
- Getter and Setter methods to change the interior color of the polygon.
- a main method for the start of program execution
- The launch method will be called here
- a class that models the polygon which will be an extension of the StackPane class
- The polygon will be instantiated here
- The constructor:
- is where the default number of sides will set (6)
- the polygon instance will be added to the pane
- the fill color will be set
- the stroke color will be set
- the paint method is initially called
- The constructor:
- The paint method will be defined here
- An ObservableList of type Double will be created
- The width and height of the polygon will be set to 200 x 200
- The radius will be calculated
- Points in the polygon will be added to the list using the following formulas for the x and y locations of the point:
- The polygon will be instantiated here
for (int i = 0; i
list.add(centerX + radius * Math.cos(2 * i * Math.PI / numberOfSides)); list.add(centerY - radius * Math.sin(2 * i * Math.PI / numberOfSides));
}
- The methods to increase and decrease the number of sides of the polygon are defined here
Submission:
Submit this YourNameAssignment1.java file in the Assignment 2 Section on or before the due date.
Provided code:
Misc. Requirements: Needs to have buttons for increasing and decreasing the number of sides for the polygon. Also would like you could provide an XFML file of the program. Would be nice if you could build it in JavaFX Scene Builder.
Formatting: Please try formatting your solution like this answer https://www.chegg.com/homework-help/questions-and-answers/project-n-sided-regular-polygon-problem-description-write-program-displays-regular-polygon-q4492944 .
private void paint ) t //Initialize the ObservableList ObservableListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started