Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Create the UI that looks like the example dialogs.
  2. Your program should correctly display an n-sided polygon.
  3. Your program should handle action events from the buttons.
  4. Your program should redisplay the polygon when the user clicks the buttons.
  5. Your program should allow for the changing of the interior color of the polygon.

Example Dialogs:

image text in transcribed

What you will need in for the code:

Your java code will have three sections:

  1. The YourNameAssignment1 class which will be an extension of the Application class
    1. The start method will be located here
    2. The panes width and height will be set to 270 x 210
    3. An instance of the polygon class (see item 3 below) is created with a default of 6 sides
    4. The polygon instance is set in the center of the BorderPane
    5. The bindings to the polygon classs methods to increase and decrease the number of sides will be located here
    6. The BorderPane, HBox and Scene will be instantiated here
    7. The states title is set
    8. The + and buttons are created and located in the HBox
    9. Getter and Setter methods to change the interior color of the polygon.
  2. a main method for the start of program execution
    1. The launch method will be called here
  3. a class that models the polygon which will be an extension of the StackPane class
    1. The polygon will be instantiated here
      1. The constructor:
        1. is where the default number of sides will set (6)
        2. the polygon instance will be added to the pane
        3. the fill color will be set
        4. the stroke color will be set
        5. the paint method is initially called
    2. The paint method will be defined here
      1. An ObservableList of type Double will be created
    1. The width and height of the polygon will be set to 200 x 200
    2. The radius will be calculated
    3. Points in the polygon will be added to the list using the following formulas for the x and y locations of the point:

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));

}

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

image text in transcribed

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 ObservableList list = polygon.ge oi s(): //clear the list list.clear //Initialize variables double radius; double centerx; double centerY; double WIDTH = 200; double HEIGHT = 200; //Calculate center point and radius centen = w1DTH / 2; centerYHEIGHT2 radius = Math . min (WIDTH, HEIGHT) * 0 . 4 ; //Add points to the observable list for (int i = 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions