Programming Project 2 100 points Submission Instructions In Eclipse, create a Ja
ID: 3784058 • Letter: P
Question
Programming Project 2 100 points Submission Instructions In Eclipse, create a Java Project called Project2. Remember to enter a comment with your name, the assignment number, the date, the file name, and a short description of what the file does at the top of each class When you are finished, compress (zip) your Java project folder and upload your project to Canvas before the due date. You can do this in Eclipse by selecting Export from the File menu. Open the General folder and select Archive File. Click Next, select your project, and Browse to the location you would like to save your zip file. Please name your zip file YourLastNameYourFirstNameProject2. Remember that late assignments are not accepted in this course. See the syllabus for more information. Assignment For this project we will create a class that add some extra features to StdDraw without modifying StdDraw itself our class will have static methods, static variables, and constants Create a new class called UnstdDraw. This class should be put in a package named unstddraw. The methods you will write are: static void filledRegularPolygon(centerX, centerY, radius, numSides) This method will draw a filled regular polygon centered at (x, y). Remember that a regular polygon has equal side lengths and equal angles. Hint: You may find it useful to use the StdDraw.filledPolygon method your method. static void spiral(centerx, centerY, maxRadius, numcoils, num Segments Per Coil) This will draw a spiral centered at (x, y). The parameter maxRadius determines how large the spiral will be. The parameter num Coils indicates the number of coils (oops) in the spiral. You will draw the spiral using line segments. The numsegments parameter indicates how many line segments should be used to draw each coilExplanation / Answer
// 12: HypotenuseCalculator.java // This program finds and displays hypotenuse of a triangle // whose sides are entered by the user. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.*; public class HypotenuseCalculator extends JFrame { // JLabel and JTextField for length of side A private JLabel lengthSideAJLabel; private JTextField lengthSideAJTextField; // JLabel and JTextField for length of side B private JLabel lengthSideBJLabel; private JTextField lengthSideBJTextField; // JLabel and JTextField for hypotenuse private JLabel lengthHypotenuseJLabel; private JTextField lengthHypotenuseJTextField; // JButton to initiate calculation of hypotenuse private JButton calculateJButton; // no-argument constructor public HypotenuseCalculator() { createUserInterface(); } // create and position GUI components; register event handlers private void createUserInterface() { // get content pane for attaching GUI components Container contentPane = getContentPane(); // enable explicit positioning of GUI components contentPane.setLayout( null ); // set up lengthSideAJLabel lengthSideAJLabel = new JLabel(); lengthSideAJLabel.setBounds( 16, 13, 96, 21 ); lengthSideAJLabel.setText( "Length of side A:" ); contentPane.add( lengthSideAJLabel ); // set up lengthSideAJTextField lengthSideAJTextField = new JTextField(); lengthSideAJTextField.setBounds( 150, 13, 90, 21 ); lengthSideAJTextField.setHorizontalAlignment( JTextField.RIGHT ); contentPane.add( lengthSideAJTextField ); // set up lengthSideBJLabel lengthSideBJLabel = new JLabel(); lengthSideBJLabel.setBounds( 16, 45, 96, 21 ); lengthSideBJLabel.setText( "Length of side B:" ); contentPane.add( lengthSideBJLabel ); // set up lengthSideBJTextField lengthSideBJTextField = new JTextField(); lengthSideBJTextField.setBounds( 150, 45, 90, 21 ); lengthSideBJTextField.setHorizontalAlignment( JTextField.RIGHT ); contentPane.add( lengthSideBJTextField ); // set up lengthHypotenuseJLabel lengthHypotenuseJLabel = new JLabel(); lengthHypotenuseJLabel.setBounds( 16, 89, 130, 21 ); lengthHypotenuseJLabel.setText( "Length of hypotenuse:" ); contentPane.add( lengthHypotenuseJLabel ); // set up lengthHypotenuseJTextField lengthHypotenuseJTextField = new JTextField(); lengthHypotenuseJTextField.setBounds( 150, 89, 90, 21 ); lengthHypotenuseJTextField.setHorizontalAlignment( JTextField.CENTER ); lengthHypotenuseJTextField.setEditable( false ); contentPane.add( lengthHypotenuseJTextField ); // set up calculateJButton calculateJButton = new JButton(); calculateJButton.setBounds( 150, 121, 90, 23 ); calculateJButton.setText( "Calculate" ); contentPane.add( calculateJButton ); calculateJButton.addActionListener( new ActionListener() // anonymous inner class { // event handler called when calculateJButton is pressed public void actionPerformed( ActionEvent event ) { calculateJButtonActionPerformed( event ); } } // end anonymous inner class ); // end call to addActionListener // set properties of application's window setTitle( "Hypotenuse Calculator" ); // set title bar string setSize( 262, 182 ); // set window size setVisible( true ); // display window } // end method createUserInterface // calculate and display hypotenuse length private void calculateJButtonActionPerformed( ActionEvent event ) { // get input from JTextFields double sideA = Double.parseDouble( lengthSideAJTextField.getText() ); double sideB = Double.parseDouble( lengthSideBJTextField.getText() ); // display error message if user enters invalid input if ( sideARelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.