Computer Science 15-111 (Sections A & B), Spring 2007

Homework #2 (part 3):  Extra Credit (1 hour)

  Due:  Mon 22-Jan-2007, 8pm (online submisson).

 

Note:  This is EXTRA CREDIT.  It is entirely OPTIONAL.  You do not even have to read this document if you do not wish to do so.

 

Note:  This assignment, if done correctly and to a reasonable coding standard, is worth 1 hour of Extra Credit (even if it requires more or less time on your part).  While it will be graded if submitted, it will not count towards your hw2 grade.  Instead, it will be taken into account at the end of the semester if you are “on the bubble”, as described in the Course Syllabus.

 

Write the following Java programs.  The same guidelines apply as during the main assignment:  use good style, and for now you do not need to use methods (until Monday, that is).

 

1.      Write a program, Goldbach.java, that demonstrates Goldbach’s Conjecture, which states that every even number greater than 2 is the sum of 2 primes.  For example:
    4 = 2 + 2
    6 = 3 + 3
    8 = 3 + 5
  10 = 5 + 5
  
This conjecture is unproven, but has been verified by computers to very large values.  Your program should read in an even number greater than 2 and should find two prime numbers summing to that number.  Seeing as the conjecture has been verified for numbers far greater than 232, it is clear that you will not find a counterexample in this assignment (right?).

2.      Write a program, Parabolas.java, that reads in 6 double values representing 3 (x,y) points, and then fits a parabola exactly through those 3 points.  Print out the equation of this parabola in the form y = ax2 + bx + c.  If no such parabola exists, print out a message saying so.  Then, read in 3 more (x,y) points and fit a second parabola through those points, and print out this second equation.  Finally, print out the points, if any, where these two parabolas intersect.

 

3.      Write a program, DecimalBaseConverter.java, that reads in an (unsigned) positive integer N in base 10 (so that you can use the default Scanner.nextInt method) followed by another positive integer B, where B is in the range [1,36], and prints out the value of N converted to base B (using uppercase letters as extra digits as needed).  Here is a sample of how your program might operate (where user input is underlined):

     Enter a positive integer (or 0 to exit):  313
     Enter a target base:   4
     313 in base 4 equals 10321

     Enter a positive integer (or 0 to exit):  33275116
     Enter a target base:   18
     33275116 in base 18 equals HAHAHA

Your program must do the base conversion manually.  It must not use any built-in Java methods that might do it for you.