# CSE 270M - homework4

CSE 270M - homework4 - due MONDAY, November 4, by 9am - 35 points

You will submit three things (files should be zipped together):
●A Logo file (FMSLogo format, or simply a text file that lists your Logo procedures so that I can copy and paste them and run them.  You could use the online Logo interpreter at https://www.calormen.com/jslogo/, useful for Mac users who can't run FMSLogo).
●A Java file (with the six methods I've highlighted below)
●Either a printed paper brought to my office, or a pdf of your work for #2.  Either way, it is due by Monday, November 4, by 9am.  If you are submitting a printout, it is due to my office, 205L Benton Hall by 5pm (just slide it under my door or ask Ms. Strecker to put it in my mailbox).

1.(10 points) In class, we examined the first two stages of creating Koch's Snowflake, using "tiny triangles" as the unit of area, and the length of one side of the tiny triangle as the unit of length.
a.At stage 0, the perimeter is 81, and the area is 729.
b.At stage 1, the perimeter is 108, and the area is 972.

In your Java file write the following two methods that should compute the area and perimeter of a stage-n Koch's snowflake (so, for example, it should give the same values shown above for stages 0 and 1).
●public static double kochArea(int n)
●public static double kochPerimeter(int n)

Then, write a method named:
●public static void kochResults()

which displays in table form the area and perimeter of Koch's Snowflake from stages 0 through 20.  The output should look something like this.

0 81.00000 729.00000
1 108.00000 972.00000

Area and perimeter should be displayed with the same number of decimal points at each stage (5 places is fine, but you might choose to show more).  Keep results right-aligned (so decimal points line up).

2.(10 points) On paper or in a pdf The "real" Koch's Snowflake is the theoretical figure that would be obtained if the construction process could be repeated infinitely.  The real Koch's Snowflake has a perimeter that is infinite, and an area that is finite. Mathematically derive the exact area of the real snowflake.  Use techniques from class for computing series to clearly demonstrate how you computed the area.  Don't use a formula.  Use the same units of measure as above and as used in class (tiny triangles).  Begin with a triangle whose sides measure 27 units.  Your arguments/proof should:
●Be clear, including clearly indicating the final result
●Be explained as you go.  If it is not entirely obvious how statement B follows from statement A, then explain why it follows.  Don't assume, "Norm surely knows what I'm thinking."  He probably doesn't.

3.(10 points) In your Logo file (either FMSLogo or a text file with Logo procedures in it that I can copy, paste, and run)
○Implement a procedure named cantor that draw's Cantor's set for any length and any given depth.  For example cantor 90 0 would draw a segment of length 90, while cantor 75 1 would draw 2 segments of length 25, and so on.
○Implement a procedure named sierpinski for any size and depth.  For example, sierpinski 100 5 should draw a stage-5 Sierpinski triangle with sides of length 100.  There is no need to shade or color in any of the triangles.

4.(5 points) The harmonic series is 1 + 1/2 + 1/3 + 1/4 + ....  You could use a loop to compute this using Java's primitive double type, but it has very limited precision.  Java's BigDecimal type uses arbitrary precision.  This means you can get as many digits of precision as you need, up to the memory limits of your computer.  Learn how to use Java's BigDecimal class (for example, learn the limitations encountered when you try to compute 1/3 using BigDecimal, and learn how scale can be used to control the number of digits after the decimal point).  Then, write the following method in your Java file:

●public static BigDecimal harmonicSum(int n, int places)

This method should compute the sum of the first n terms of the harmonic series, and return the result with the specified number of places after the decimal point (rounding the last digit down).  For example:

harmonicSum(2, 3) should return 1.500
harmonicSum(7, 21) should return 2.592857142857142857142

Then, write a method named:
●public static void harmonicResults()

which displays in table form the harmonic sum for the first n terms, as n goes from 1 to 20, rounding each answer to 20 places after the decimal point.  For example, the first 3 lines of output should be the following:

1 1.00000000000000000000
2 1.50000000000000000000
3 1.83333333333333333333

5.In your Java file, Implement the following method so that when your Java main() method is called, it displays kochResults() followed by harmonicResults():

●public static void main(String[] args)

Extra credit: What is the smallest value of n for which your harmonicSum() method would return a value greater than 50?  Explain.