CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

Shapes World Problem Solving
Money
 
The Problem :   Money.   Three coins,  a quarter a nickel,  and a dime are placed on a dollar bill in such a way tat they enither overlap one another nor overhang any edge of the bill.   What is the area of the dollar bill which is not obscured by the three coins?
 
  JavaApplication  -- Money

   // General Information
   // ---------------------------------------------------
  
   // File:  MoneyApp.java
   // Type:  java application file
   // Date:  Wed Sep 27, 2000
   // Name:  James W. Bremenour
   // Line:  Calculates a specific area
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      Calculates the area of a dollar bill that has not
      been obstructed by three coins. The coins being a 
      quarter, nickel, and a dime
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class MoneyApp
      {
         static public void main (String args[])
         {
         // Establish coin radii. The dimensions of the
         // coins were acquired from:
         // http://www.usmint.gov/circulating/
         // specifications.cfm
         // The dimensions of the dollar were acquired 
         // from: http://www.bep.treas.gov/faqforum.cfm
             double qradius = 0.955/2.0;
             double nradius = 0.835/2.0;
             double dradius = 0.705/2.0;
         // Create the required shapes
             Circle quarter = new Circle(qradius);
             Circle nickel = new Circle(nradius);
             Circle dime = new Circle(dradius);
             Rectangle dollar = new Rectangle(6.14,2.61);
         // Do the math to determine unobstructed dollar 
         // area
             double unobstructedArea = 
                 (dollar.area() - 
                  (quarter.area() + nickel.area() + 
                   dime.area()));
         // Display the result
             IO.print("The unobstructed dollar area is:");
             IO.print("  " + unobstructedArea);
             IO.print(" square inches");
             IO.println();
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   $ java MoneyApp
   The unobstructed dollar area is:  14.371135483390038 squar+
   e inches
   $ 
   */