



|
|
My Intro to Object-Oriented Programming
|
Programming Challenge Archive
Programming Assignment # 1
Painted Disks
|
|
|
Three disks of differing radii are given. Different portions of the disks are different colors. Display results for the total collective area of the disks, as well as the collective areas of the colors.
JavaApplication - Programming Assignment # 1 --
Painted Disks
// General Information
// ---------------------------------------------------
// File: PaintedDisksApp.java
// Type: java application file
// Date: Mon Sep 18, 2000
// Name: Jeffrey R. Norkoli
// Line: Display requested features of three disks.
// Application Description
// ---------------------------------------------------
/*
Three disks of differing radii are given.
Different portions of the disks are different
colors. Display results for the total collective
area of the disks, as well as the collective areas
of the colors.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
// Application Class
// ---------------------------------------------------
class PaintedDisksApp
{
static public void main (String args[])
{
// Record radius properties of all the
// disks. The radius of Disk1 is given and
// the radii of Disk2 and Disk3 need to be
// calculated.
double radiusDisk1 = 10.24;
double radiusDisk2 = radiusDisk1 * 2;
double radiusDisk3 = (radiusDisk1
+ radiusDisk2) / 2;
// Calculate total areas for each disk.
double areaDisk1 = Math.PI *
Math.pow(radiusDisk1,2);
double areaDisk2 = Math.PI *
Math.pow(radiusDisk2,2);
double areaDisk3 = Math.PI *
Math.pow(radiusDisk3,2);
// Calculate color areas for Disk1.
double blueAreaDisk1 = (1.0/3.0) * areaDisk1;
double redAreaDisk1 = (2.0/3.0) * areaDisk1;
// Calculate color areas for Disk2.
double redAreaDisk2 = (1.0/2.0) * areaDisk2;
double blueAreaDisk2 = (1.0/2.0) * areaDisk2;
// Calculate color areas for Disk3.
double redAreaDisk3 = (1.0/5.0) * areaDisk3;
double blueAreaDisk3 = (2.0/5.0) * areaDisk3;
double yellowAreaDisk3 = (2.0/5.0) * areaDisk3;
// Total various results.
double totalBlueArea = blueAreaDisk1
+ blueAreaDisk2 + blueAreaDisk3;
double totalRedArea = redAreaDisk1
+ redAreaDisk2 + redAreaDisk3;
double totalYellowArea = yellowAreaDisk3;
double totalDiskArea = areaDisk1
+ areaDisk2 + areaDisk3;
// Display 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 "
+ totalYellowArea + " square units.");
IO.println ("The collective area is "
+ totalDiskArea + " square units.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac PaintedDisksApp.java
$ java PaintedDisksApp
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.
$
*/
|
|
|