This is not a current assignment. If you are currently enrolled in SE1010, do not do this assignment expecting to receive credit for it.

Lab 5

Assignment

Write a program that prompts the user to enter:

  • Desired number of steps (between 1 and 10,000)
  • Desired number of cycles for the sine term (between 1 and 25)
  • Desired number of cycles for the cosine term (between 1 and 25)

The program should then display a plot similar to the one shown below:

The user should enter these values with through JOptionPane dialogs. They should look something like this:

The plot consists of a number of connected line segments that approximate a curve; the number of line segments (or “steps”) is specified by the first user-entered value. The first line segment begins at

x = drawWidth * sin(0), y = drawHeight * cos(0)

where drawWidth is 40% of the width of the window and drawHeight is 40% of the height of the window.

The first line segment ends at

x = drawWidth * sin(sineCycles * stepSize), y = drawHeight * cosine(cosineCycles * stepSize)

where drawWidth and drawHeight are 40% of the window width and height, sineCycles is the second value entered by the user, and cosineCycles is the third value entered by the user.

Also, stepSize = 2 * PI / steps where steps is the first value entered by the user.

The second line segment goes from the end of the first line segment to

x = drawWidth * sin(2 * sineCycles * stepSize), y = drawHeight * cosine(2 * cosineCycles * stepSize)

The third line segment goes from the end of the second line segment to

x = drawWidth * sin(3 * sineCycles * stepSize), y = drawHeight * cosine(3 * cosineCycles * stepSize)

Since the number of cycles is an integer value, the last line segment goes from the end of the second to last line segment back to the beginning of the first line segment. In the example shown above, this results in ten line segments that trace a circle.

Details

  • You should make use of the WinPlotter class used in previous lab assignments.
  • The size of the window should be 500 x 500.
  • The background for the window should be black.
  • A grid with an increment of 10 pixels in both the horizontal and vertical directions should be drawn in gray. You'll need to make use of the Color class in the java.awt package for this.
  • You should change the logical window coordinates to go from (-width/2, -height/2) to (width/2, height/2). Hint: use the setPlotBoundaries from the WinPlotter class.
  • The title of the window should be set as shown in the example result.
  • The drawWidth and drawHeight should be calculated by your program and be based on the window size.
  • If any of the numbers entered by the user are outside of the specified range, the user should be asked again to enter a number within the specified range. This process should be repeated until the user enters a number within the range. HINT: You may find it helpful to write a method to accept and check a single numeric value.
  • Your program need not handle user input that doesn't match the specified type. That is, your program may fail if the user enters a floating point number or a non-numeric character instead of an integer.

Extras

Once you've completed the assignment requirements, you may wish to add some additional features. Some things you may consider:

  • Allow the user to display more than one shape in the same window. You may wish to give each shape a different color.
  • Develop a mechanism for drawing dotted lines instead of solid lines.
  • Change the color of each line as the shape is drawn.

Can you produce the following?

Deliverables

Record the time you spent on this assignment in FAST, and demonstrate/submit your assignment as specified by your instructor.

se1010labs/lab5.txt · Last modified: 2009/06/03 11:22 (external edit)
 

This website is not owned or managed by the Milwaukee School of Engineering.

© 2003-2010 Dr. Christopher C. Taylor, et. al. • Office: L-343 • Phone: 277-7339 • npǝ˙ǝosɯ@ɹolʎɐʇ • -> RSS <-