CS 120   Fall 2016,  Instructor:  Jeffrey Horn
 

 Assignment 6:   "Square Pyramids and Perfect Squares"


  • Handed out:  Tuesday, Oct. 18, 2016
  • Due:    Tuesday, Oct. 25, 2016
  • Purpose:  Learn
    1. Problem solving
    2. Method calling
    3. Function calling
    4. Using loops to solve problems
  • Example Code:   (in class)
  • DETAILS:
    1. THE PROBLEM:  Consider the series of square pyramids made of layers of spheres.   Each layeris a k by k square of k spheres, with the first layer (k = 1) having one sphere, the next layer having four spheres, the next nine, and so on.  For what height h is the total number of spheres in the pyramid, call it T, a perfect square?   (That is, for what T is the square root of T an integer?  Or to put it another way, for what value of T is there an integer n such that n*n = T?)  We are interested in the non-trivial case of h > 1 (note that h = 1, T=1 does solve the problem!)  It was proven about one hundred years ago that there is exactly one such non-trival solution.
    2. To be clear, I want you to find the height h and the corresponding T that solves the problem.  Your code should print these two values out (to the graphics window OR to the console window), and clearly label them (as height and total number of spheres, and as the solution!).
    3. Write code that does this.   You are free to use our class of useful math functions, CS120math.
    4. Send me the code (that is, all source code files).   Please zip them up in a compressed folder if more than one file.
    5. STYLE:  main comment, descriptive variable names, describe var.s in comments, comment all logical groups of code such as methods, loops, if-then's.
    6. TURN IN BY EMAIL:   Send me your java code.  Use SUBJECT LINE:  "CS120:  A6  ..."
  • GRADING:  TOTAL: 100 pts.
  •