CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

General Problems Solving
Painted Disks
 
The Problem :   Painted Disks.   A circular disk is of radius 10.24 is painted in a way such that one-third of the disk is blue and two-thirds is red.   A larger circular disk of radius twice the smaller disk is painted in sch a way that half of it is blue and half is red.   A third circular disk whose radius is the average of the radii of the first two is painted in such a way that one-fifth of the disk is red,  and the remaining area of the disk is half yellow and half blue.   Answer the following four questions:   What is the collective blue area of the three disks?   What is the collective red area of the three disks?   What is the collective yellow area of the three disks?   What is the collective area of the three disks?
 
  JavaApplication  -- Painted Disks

   // General Information
   // ---------------------------------------------------
  
   // File:  PaintedDisksApp.java
   // Type:  java application file
   // Date:  Mon Sep 18, 2000
   // Name:  James W. Bremenour
   // Line:  Calculates various area's.
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      Claculates the area of three circles, each of which
      is painted a certain fraction of certain colors.
      The area of the colors is also determined.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.math.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class PaintedDisksApp
      {
         static public void main (String args[])
         {
         // Find the radius of all circles
     double firstDiskRadius = 10.24;
     double secondDiskRadius = 
         firstDiskRadius * 2;
     double thirdDiskRadius = 
         (firstDiskRadius + secondDiskRadius)/2;
         // Find the area for all the disks
     double firstDiskArea = 
         Math.pow(firstDiskRadius, 2) * Math.PI;
     double secondDiskArea =
         Math.pow(secondDiskRadius, 2) * Math.PI;
     double thirdDiskArea = 
         Math.pow(thirdDiskRadius, 2) * Math.PI;
         // Find the area for the colors
     double firstDiskBlueArea = firstDiskArea/3;
     double firstDiskRedArea = 
         (firstDiskArea *2 )/3;
     double secondDiskBlueArea = 
         secondDiskArea/2;
     double secondDiskRedArea = secondDiskArea/2;
     double thirdDiskRedArea = thirdDiskArea/5;
     double thirdDiskBlueArea = 
         (thirdDiskArea/5)/2;
     double thirdDiskYellowArea =
         (thirdDiskArea/5)/2;
         // Determine the answers to the four questions
     double totalBlueArea = 
         (firstDiskBlueArea + secondDiskBlueArea 
          + thirdDiskBlueArea);
     double totalRedArea = 
         (firstDiskRedArea + secondDiskRedArea +
          thirdDiskRedArea);
     double totalYellowArea = 
         thirdDiskYellowArea;
     double totalDiskArea = 
         (firstDiskArea + secondDiskArea +
          thirdDiskArea);
         // Display the results
     IO.print ("The total blue area is:  ");
     IO.print (totalBlueArea + " square units");
     IO.println();
     IO.print ("The total red area is:  ");
     IO.print (totalRedArea + " square units");
     IO.println();
     IO.print ("The total yellow area is:  ");
     IO.print (totalYellowArea + " square units");
     IO.println();
     IO.print ("The total area is:  ");
     IO.print (totalDiskArea + " square units");
     IO.println();
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   rocky - bremenou - pdisks > java PaintedDisksApp
   The total blue area is:  842.7658234229044 square units
   The total red area is:  1026.6919151796947 square units
   The total yellow area is:  74.11946981243784 square units
   The total area is:  2388.294027289664 square units
   rocky - bremenou - pdisks > 
   */