P Dunn's Super CS1 Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
P Dunn's Super CS1 Site  
 
 
Programming Challenge Archive

Shapes World Programming Challenge
Money Application
 
 
  Java Application  -- MoneyApp

   // General Information
   // ---------------------------------------------------
  
   // File:  MoneyApp.java
   // Type:  java application file
   // Date:  Wed Sep 27, 2000
   // Name:  Patrick Dunn
   // Line:  A program to find the exposed area of a dollar b+
   ill
   //        with three coins covering it.
  
   // Application Description
   // ---------------------------------------------------
  
   /*
     This program will find the left over area of a dollar bi+
   ll after
     three coins, a quarter, nickel and a dime cover it.  Thi+
   s will use
     the shapes class to achieve it.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class MoneyApp
      {
         static public void main (String args[])
         {
     // setup variables for given data, sizes in inches
     double dollarBillLength = 7.25;
     double dollarBillWidth = 3.6;
  
     // these are diameters, we divide by 2 for the radius, +
   size in inches
     double radiusOfQuarter = .955 / 2;  
     double radiusOfNickel = .835 / 2;
     double radiusOfDime = .705 / 2;
  
     // model the dollar bill
     Rectangle dollarBill = new Rectangle(dollarBillLength,d+
   ollarBillWidth);
  
     // model the quarter
     Circle quarter = new Circle(radiusOfQuarter);
  
     // model the Nickel
     Circle nickel = new Circle(radiusOfNickel);
     
     // model the Dime
     Circle dime = new Circle(radiusOfDime);
  
     // find the area of the dollar bill
     double areaOfDollarBill = dollarBill.area();
  
     // find the area of the coins
     double areaOfQuarter = quarter.area();
     double areaOfNickel = nickel.area();
     double areaOfDime = dime.area();
  
     // add up the area of the coins
     double coinArea = areaOfQuarter + areaOfNickel + areaOf+
   Dime;
  
     // subtract the total area of the dollar bill - the are+
   a of the coins
     // this will give us our dollar bill area leftover
     double areaLeftOver = areaOfDollarBill - coinArea;
  
     // display
     IO.println("The unobscured area is " + areaLeftOver + "+
    square inches");
         
     
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   $ java MoneyApp
   The unobscured area is 24.44573548339004 square inches
   $ 
   */