CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

General Problems Solving
Painted Disks
 
 

 
  JavaApplication  -- PaintedDisks

   
   // General Information
   // ---------------------------------------------------
  
   // File:  PaintedDisksApp.java
   // Type:  java application file
   // Date:  Tue Sep 19, 2000
   // Name:  Kara Becker
   // Line:  Compute the areas of the disks.
  
   // Application Description
   // ---------------------------------------------------
  
   /*
     Compute the areas of three circular disks having differe+
   nt sizes, and determining each of the following: the colle+
   ctive blue area of the three disks, the collective red are+
   a of the three disks, the collective yellow area of the th+
   ree disks, and the collective area of the three disks.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
   import blue.io.*;
  
  
   // Application Class
   // ---------------------------------------------------
  
   class PaintedDisksApp
   {
       static public void main (String args[])
       {
   //Determine the area of disk one.
   double radDiskOne = 10.24;
   double areaDiskOne = Math.PI * Math.pow(10.24,2);
   //Determine the radius and area of disk two.
   double radDiskTwo = radDiskOne * 2;
   double areaDiskTwo = Math.PI * Math.pow(radDiskTwo,2);
   //Determine the radius and area of disk three.
   double radDiskThree = (radDiskOne + radDiskTwo) / 2;
   double areaDiskThree = Math.PI * Math.pow(radDiskThree,2)+
   ;
   //Determine the collective blue area of the three disks.
   double blueArDiskOne = areaDiskOne * (1.0/3.0);
   double blueArDiskTwo = areaDiskTwo * (1.0/2.0);
   double blueArDiskThree = areaDiskThree * (2.0/5.0);
   double totalBlueArea = blueArDiskOne + blueArDiskTwo + bl+
   ueArDiskThree;
   //Determine the collective red area of the three disks.
   double redArDiskOne = areaDiskOne * (2.0/3.0);
   double redArDiskTwo = areaDiskTwo * (1.0/2.0);
   double redArDiskThree = areaDiskThree * (1.0/5.0);
   double totalRedArea = redArDiskOne + redArDiskTwo + redAr+
   DiskThree;
   //Determine the collective yellow area of the three disks+
   .
   double totalYelArea = areaDiskThree * (2.0/5.0);
   //Determine the collective area of the three disks.
   double totalAreaOfDisks = areaDiskOne + areaDiskTwo + are+
   aDiskThree;
   //Display the results.
   IO.println("The collective blue area is " + totalBlueArea+
    + " square units.");
   IO.println("The collective red area is " + totalRedArea ++
    " square units.");
   IO.println("The collective yellow area is " + totalYelAre+
   a + " square units.");
   IO.println("The collective area is " + totalAreaOfDisks ++
    " square units.");
       }
   }
  
   // Demo
   // ---------------------------------------------------
  
   /*
     $ javac PaintedDisksApp.java
     $ java PaintedDisksApp
     The collective blue area is 1065.124232860218 square uni+
   ts.
     The collective red area is 1026.6919151796947 square uni+
   ts.
     The collective yellow area is 296.47787924975137 square +
   units.
     The collective area is 2388.294027289664 square units.
     $
   */