CS1150 (Fall 2012, Section 4): Programming Assignment 3

Output and Documentation


Instructions

  1. Start a program called CircleMath. It will involve keyboard input, so we might as well add the import line right off the bat:
    /* CircleMath.java
     * Your name
     * CS1150.1208-4, Programming Assignment #3
     * This program computes various numbers for a circle of radius r.
     */
    import java.util.Scanner;
    
    public class CircleMath {
      public static void main(String[] args) {
        // Code will go here
      }
    }
    
  2. Write code to prompt the user for a radius. Let's assume this will always be an integer, specifying this in the prompt.
  3. Use Math.PI (or declare your own variable) to use in our calculations.
  4. Compute the perimeter (circumference), area, and volume of a sphere with radius r, using the following formulae. Keep in mind that x2 is the same as x * x and x3 is the same as x * x * x:
    C = 2 pi r
    A = pi r2
    V = 4/3 pi r3
    
  5. Print out the results of these computations using printf and the format string "A circle with radius %d has perimeter %.2f, area %.2f\n and a sphere with the same radius would have volume %.2f.\n"

Deliverables

Zip up only the file CircleMath.java, name the resulting zip file cs1150.1208-4-yourlastname-yourfirstname-pa3.zip, and submit this file as per the syllabus.