P Dunn's Super CS1 Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
P Dunn's Super CS1 Site  
 
 
Programming Challenge Archive

General Problems Solving
Painted Disks
 
 
  Java Application  -- ColoredDisks

   // General Information
   // ---------------------------------------------------
  
   // File:  ColoredDisks.java
   // Type:  java application file
   // Date:  Sun Sep 24, 2000
   // Name:  Patrick Dunn
   // Line:  A program to figure out areas of various disks
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      This program will determine and display the total
      area of 3 disks with varying radii and it will also
      find out the total area of various colored regions
      and separate/display the area of these colored regions.+
  
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.math.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class ColoredDisks
      {
         static public void main (String args[])
         {
     double radiusOfDiskOne = 10.24; // radius of disk one i+
   n square units
     double areaOfDiskOne;           // area of disk one in +
   square units
     double radiusOfDiskTwo;         // radius of disk two i+
   n square units
     double areaOfDiskTwo;           // area of disk two in +
   square units
     double radiusOfDiskThree;     // radius of disk three i+
   n square units
     double areaOfDiskThree;         // area of disk three i+
   n square units
     double areaOfBlueDisk1;          // area of blue region+
    on disk 1
     double areaOfRedDisk1;           // area of red region +
   on disk 1
     double areaOfBlueDisk2;          // area of blue region+
    on disk 2
     double areaOfRedDisk2;           // area of red region +
   on disk 2
     double areaOfBlueDisk3;          // area of blue region+
    on disk 3
     double areaOfRedDisk3;           // area of red region +
   on disk 3
     double areaOfYellowDisk3;        // area of yellow regi+
   on on disk 3
     double areaOfBlue = 0.0;         // total area of blue +
   region
     double areaOfRed = 0.0;          // total area of red r+
   egion
     double areaOfYellow = 0.0;       // total area of yello+
   w region
     double areaCollective = 0.0;     // collective area on +
   disks
     double tempArea;                 // temp variable
  
     // Begin Disk 1 work
  
     // compute area of the first disk
     areaOfDiskOne = Math.PI*(radiusOfDiskOne * radiusOfDisk+
   One);
  
     // compute and store the area of the blue part of the d+
   isk
     areaOfBlueDisk1 = areaOfDiskOne - (areaOfDiskOne * .66)+
   ;
     areaOfRedDisk1 = areaOfDiskOne - areaOfBlueDisk1;
  
     // add to the total blue and red areas
     areaOfBlue = areaOfBlue + areaOfBlueDisk1;
     areaOfRed = areaOfRed + areaOfRedDisk1;
  
     // display the area of the disk and blue/red areas
     IO.println("Colored Disk Area Problem");
     IO.println("-------------------------");
     IO.println("Disk 1 Results");
     IO.println("-------------------------");
     IO.println("The total area of Disk One: " + areaOfDiskO+
   ne + 
    " square units.");
     IO.println("The Red area on Disk One is: " + areaOfRedD+
   isk1 + 
    " square units.");
     IO.println("The Blue area on Disk One is: " + areaOfBlu+
   eDisk1 +
    " square units.");
  
     // Begin disk 2 work
  
     // compute the radius of Disk 2
     radiusOfDiskTwo = radiusOfDiskOne * 2.0;
  
     // compute the area of Disk 2 now that we have the area+
  
     areaOfDiskTwo = Math.PI*(radiusOfDiskTwo * radiusOfDisk+
   Two);
  
     // compute the area of the colored regions
     areaOfRedDisk2 = areaOfDiskTwo / 2.0;
     areaOfBlueDisk2 = areaOfDiskTwo / 2.0;
  
     // add to the total blue and red areas
     areaOfBlue = areaOfBlue + areaOfBlueDisk2;
     areaOfRed = areaOfRed + areaOfRedDisk2;
  
     // display the area of the disk and blue/red areas
     IO.println("-------------------------");
     IO.println("Disk 2 Results");
     IO.println("-------------------------");
  
     IO.println("The total area of Disk Two: " + areaOfDiskT+
   wo + 
    " square units.");
     IO.println("The Red area on Disk Two is: " + areaOfRedD+
   isk2 + 
    " square units.");
     IO.println("The Blue area on Disk Two is: " + areaOfBlu+
   eDisk2 +
    " square units.");
  
     // Begin disk 3 work
     
     // find the radius of disk three by taking the average +
   of 
     // the radius of disk one and disk two
     radiusOfDiskThree = (radiusOfDiskOne + radiusOfDiskTwo)+
    / 2;
     
     // find the area of disk three
     areaOfDiskThree = Math.PI*(radiusOfDiskThree * radiusOf+
   DiskThree);
  
     // find the area that is red
     areaOfRedDisk3 = areaOfDiskThree - (areaOfDiskThree * (+
   .2));
     
     // find the area that is blue
     areaOfBlueDisk3 = areaOfDiskThree - (areaOfDiskThree * +
   (.4));
     
     // find the area that is yellow
     areaOfYellowDisk3 = areaOfDiskThree - (areaOfDiskThree +
   * (.4));
  
     // add to the total blue, red and yellow areas
     areaOfBlue = areaOfBlue + areaOfBlueDisk3;
     areaOfRed = areaOfRed + areaOfRedDisk3;
     areaOfYellow = areaOfYellow + areaOfYellowDisk3;
  
     // compute and store the collective area of the disks
     areaCollective = areaOfDiskOne + areaOfDiskTwo + areaOf+
   DiskThree;
  
     IO.println("-------------------------");
     IO.println("Disk 3 Results");
     IO.println("-------------------------");
     IO.println("The total area of Disk Three: " + areaOfDis+
   kThree + 
    " square units.");
     IO.println("The Red area on Disk Two is: " + areaOfRedD+
   isk3 + 
    " square units.");
     IO.println("The Blue area on Disk Two is: " + areaOfBlu+
   eDisk3 +
    " square units.");
     IO.println("The Yellow area on Disk Three is: " + 
    areaOfYellowDisk3 + " square units.");
  
  
     IO.println("-------------------------");
     IO.println("Collective Results");
     IO.println("-------------------------");
     
     // display total of the colored areas
     IO.println("The collective red area is " + areaOfRed +
    " square units");
     IO.println("The collective blue area is " + areaOfBlue +
   +
    " square units");
     IO.println("The collective yellow area is " + areaOfYel+
   low +
    " square units");
     IO.println("The collective area is " + areaCollective ++
  
    " square units");
  
  
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   [patdunn@enterpriseb disks]$ javac ColoredDisks.java
   [patdunn@enterpriseb disks]$ java ColoredDisks
   Colored Disk Area Problem
   -------------------------
   Disk 1 Results
   -------------------------
   The total area of Disk One: 329.41986583305709 square unit+
   s.
   The Red area on Disk One is: 217.4171114498177 square unit+
   s.
   The Blue area on Disk One is: 112.00275438323939 square un+
   its.
   -------------------------
   Disk 2 Results
   -------------------------
   The total area of Disk Two: 1317.6794633322284 square unit+
   s.
   The Red area on Disk Two is: 658.83973166611418 square uni+
   ts.
   The Blue area on Disk Two is: 658.83973166611418 square un+
   its.
   -------------------------
   Disk 3 Results
   -------------------------
   The total area of Disk Three: 741.19469812437842 square un+
   its.
   The Red area on Disk Two is: 592.95575849950274 square uni+
   ts.
   The Blue area on Disk Two is: 444.71681887462705 square un+
   its.
   The Yellow area on Disk Three is: 444.71681887462705 squar+
   e units.
   -------------------------
   Collective Results
   -------------------------
   The collective red area is 1469.2126016154346 square units+
  
   The collective blue area is 1215.5593049239806 square unit+
   s
   The collective yellow area is 444.71681887462705 square un+
   its
   The collective area is 2388.294027289664 square units
   [patdunn@enterpriseb disks]$ 
   */