Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

General Problems Solving ( Basic Programming Apps )
Painted Disks
 
 

 
  JavaApplication  -- Painted Disks

   // General Information
   // ---------------------------------------------------
  
   // File:  PaintedDisksApp.java
   // Type:  java application file
   // Date:  Wed Sep 20, 2000
   // Name:  Byron Bahr
   // Line:  Compute the painted area of three disks
   // Application Description
   // ---------------------------------------------------
  
   /*
      Three disks are painted red, blue and yellow. 
      Calculate the painted areas of the three disks.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.shapes.*;   
  
   // Application Class
   // ---------------------------------------------------
  
      class PaintedDisksApp
      {
         static public void main (String args[])
        {
         //Define Disk Radii Values
  
             double radiusSmallDisk = 10.24;      
             double radiusLargeDisk = radiusSmallDisk * 2;
             double radiusAverageDisk = 
                    (radiusSmallDisk + radiusLargeDisk)/2;
  
         //Create small disk and compute painted 
         //areas of small disk.
  
             Circle smallDisk = new Circle(radiusSmallDisk);
             double areaSmallDisk = smallDisk.area();
             double blueAreaSmallDisk = areaSmallDisk / 3;
             double redAreaSmallDisk = (2*areaSmallDisk)/3;
  
         //Create Large disk and compute painted areas
         //of large disk.
     
             Circle largeDisk = 
                    new Circle(radiusLargeDisk);
             double areaLargeDisk = largeDisk.area();
             double blueAreaLargeDisk = areaLargeDisk/2;
             double redAreaLargeDisk = areaLargeDisk/2;
  
         //Create average disk and compute painted 
         //areas of average disk.
  
             Circle averageDisk = 
                    new Circle(radiusAverageDisk);
             double areaAverageDisk = averageDisk.area();
             double redAreaAverageDisk = 
                    areaAverageDisk/5;
             double blueAreaAverageDisk = 
                (areaAverageDisk - redAreaAverageDisk)/2;
             double yellowAreaAverageDisk = 
                (areaAverageDisk - redAreaAverageDisk)/2;
  
          //Calculate the collective blue area
          //of the three disks.
  
             double blueAreaAllDisks = 
                    blueAreaSmallDisk + 
                    blueAreaLargeDisk +
                    blueAreaAverageDisk;
  
          //Calculate the collective red area 
          //of the three disks.
  
             double redAreaAllDisks = 
                    redAreaSmallDisk +
                    redAreaLargeDisk +
                    redAreaAverageDisk;
  
         //Calculate the collective yellow area 
         //of the three disks.
  
             double yellowAreaAllDisks = 
                    yellowAreaAverageDisk;
  
         //Calculate the collective area 
         //of the three disks.
  
             double totalAreaAllDisks = 
                    areaSmallDisk +
                    areaLargeDisk +
                    areaAverageDisk;
  
         //Print the Results.
  
        IO.print ("The collective blue area is ");
        IO.print (blueAreaAllDisks);
        IO.print (" square units");
        IO.println ();
  
        IO.print ("The collective red area is ");
        IO.print (redAreaAllDisks);
        IO.print (" square units");
        IO.println ();
  
        IO.print ("The collective yellow area is ");
        IO.print (yellowAreaAllDisks);
        IO.print (" square units");
        IO.println ();
  
        IO.print ("The collective area is ");
        IO.print (totalAreaAllDisks);
        IO.print (" square units");
        IO.println ();
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   The collective blue area is 1065.124232860218 square units+
  
   The collective red area is 1026.6919151796947 square units+
  
   The collective yellow area is 296.47787924975137 square un+
   its
   The collective area is 2388.294027289664 square units
  
   */