Pages

PA12-APCSA-17-18

Due date: Saturday, 24 March 2018.

Objectives

  • Provide opportunities to practice reading, comprehending, and modifying object-oriented source code.
  • Provide opportunities to practice using custom data types.
  • Provide opportunities to practice using functions provided by Java's standard Math library.
  • Introduce standard Java library interfaces and classes that are related to sorting.
  • Highlight the effects of rounding and truncation when performing calculations involving floating point numbers.

The Assignment

Part 1. Random points on a circle.

Provide the missing code for the program posted at Points on a Circle, Version 2.1.

The completed program should generate and print coordinates for n random points on the circumference of a circle specified by the command-line arguments followed by a list of chord identifiers and chord lengths for all chords formed by connecting any two of the points on the circumference of the circle. If the command-line arguments passed to your program are 8 4 2 1, then the output of your program should look something like this:

Polar Coordinates

p1: (1.7639369128265872, 3.602090845334902)
p2: (2.4674577776258806, 4.714744620399694)
p3: (2.637635651030554, 4.826207886386146)
p4: (2.717140367116026, 4.873782513090528)
p5: (2.9437975150619597, 2.2126777943310865)
p6: (3.3403321820185106, 2.0238790952177523)
p7: (3.4962649148290077, 5.254390349881039)
p8: (6.09232184982847, 0.17472366741548145)

Cartesian Coordinates

p1: (-1.5801897478971862, -0.783883787989532)
p2: (0.005812436900730929, -2.4674509316182407)
p3: (0.2995650273234423, -2.6205691408532)
p4: (0.43662756992418167, -2.681829252542659)
p5: (-1.7624618772947074, 2.357895659431898)
p6: (-1.4621947805892725, 3.0032991042928163)
p7: (1.8035536853792078, -2.9951731934262775)
p8: (5.999563892297296, 1.059064976354103)
Chord Lengths
p3-p4: 0.15012975011097723
p2-p3: 0.33126389839427717
p2-p4: 0.48120654954435765
p5-p6: 0.7118328005945296
p4-p7: 1.4023806296442645
p3-p7: 1.5499387341971151
p2-p7: 1.8735966433810514
p1-p2: 2.3129637388618733
p1-p3: 2.6280964785160936
p1-p4: 2.769431183453014
p1-p5: 3.1470623167320366
p1-p6: 3.7890205953393927
p1-p7: 4.042217269870327
p2-p5: 5.139140373058761
p3-p5: 5.388605266954228
p4-p5: 5.4986199709787575
p2-p6: 5.6642873467033406
p7-p8: 5.834667839206012
p3-p6: 5.893359963513037
p4-p6: 5.993847741851996
p5-p7: 6.4320924384427896
p4-p8: 6.703771338475919
p3-p8: 6.784518722593312
p6-p7: 6.8298450165050495
p2-p8: 6.954234031023865
p6-p8: 7.7108941658305445
p1-p8: 7.800584939223291
p5-p8: 7.86994315043728

In the example above, the radius of the circle that the points are on is 4.0, and the circle is centered at the point identified by the Cartesian coordinates (2.0, 1.0).

Part 2. Check and color your work.
  1. Check your work.
    1. Use your program to generate at least three random points on the circumference of a circle. Pass your program a radius value that is approximately equal to the radius of some circular object you can trace around to produce a circle on a piece of graph paper. Also pass your program non-integral x- and y-coordinate values, i.e. values with digits after the decimal place; choose these values carefully so that you can complete the next step.
    2. Locate and mark the origin and plot the points your program produced on a piece of graph paper.
    3. Use your circular object to form a circle on the graph paper such that the points you plotted are on or very close to being on the circumference of the circle. If you cannot do this, then something is awry: figure out what went wrong and fix the problem.
    4. Label the points you plotted using the same labels your program produced and associated with said points. If the labels are not ordered, from smallest to largest, in a counterclockwise direction beginning at the point on the circumference of your circle with the greatest x-coordinate value, then something is amiss: figure out what went wrong and fix the problem.
    5. Connect the points you plotted with straight lines to produce all of the chords that can be formed by connecting any two points. If the chords you draw do not correspond one-to-one with the chords your program printed, then an error has occurred: figure out what went wrong and fix the problem.
    6. Measure and record the lengths of the chords you drew. If your measurements are not reasonably close to the chord lengths your program printed, then something is unsatisfactory: figure out what went wrong and fix the problem.
    7. Measure and record the distance from the origin to each one of the points you plotted. if your measurements are not reasonably close to the radius values of the points' polar coordinates, then something is not as it should be: figure out what went wrong and fix the problem.
    8. Use your program to generate 10 random points on the circumference of a circle. Plot the points and draw a circle connecting them. Are some of the points in each quadrant of the circle? If not, something might be out of whack. Try again. If there is still a quadrant that does not contain any points, then something is probably incorrect: figure out what went wrong and fix the problem.
  2. Color your work.
    1. Put a (thin) piece of blank paper on top of your grid paper and mark the locations of the points you plotted. Redraw the circle that the points are on. Connect the points to form all possible chords as before.
    2. "Color" the pieces of the circle such that no two adjacent regions are the same color. Regions are adjacent if and only if their perimeters have more than one point in common. Use the fewest number of colors possible.
    3. Repeat the previous two steps six times: put 2, 3, 4, 5, 6, and 7 points anywhere you like on the circumferences of your circles such that no three chords intersect at a single point.

Submitting your work.

Email your source code to Mr. Spurgeon at jspurgeon@vcstudent.org. Do NOT submit a hardcopy of your code. Do submit a hardcopies of the following items:
  • Submit graph papers showing all your work from part 2A above. Also submit all of the measurements you made in part 2A.
  • Submit the circles you colored in step 2B.
  • List several things that could go wrong that would prevent someone from being able to successfully perform the steps listed in section 2A above.
  • Answer the following questions:
    • What is the maximum number of colors needed to color the regions of a circle formed by all chords connecting n points on the circumference of a circle. How do you know?
    • What is the Four Color Theorem and how was it first successfully proved?