



|
|
CS1 Course Site
|
Programming Challenge Archive
Shapes World
Money App
|
|
|
JavaApplication --
MoneyApp
// General Information
// ---------------------------------------------------
// File: MoneyApp.java
// Type: java application file
// Date: Thu Sep 28, 2000
// Name: Kara Becker
// Line: Compute the area of a figure.
// Application Description
// ---------------------------------------------------
/*
Compute the area of a dollar bill that is not obscured by +
the three coins.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class MoneyApp
{
static public void main (String args[])
{
//Record the dimensions of the dollar bill and the three c+
oins.
double lengDollar = 6.125;
double widthDollar = 2.5625;
double diameterOfNickel = .8125;
double diameterOfDime = .6875;
double diameterOfQuarter = .9375;
//Create the coins.
double radiusOfNickel = diameterOfNickel / 2.0;
Circle nickel = new Circle(radiusOfNickel);
double radiusOfDime = diameterOfDime / 2.0;
Circle dime = new Circle(radiusOfDime);
double radiusOfQuarter = diameterOfQuarter / 2.0;
Circle quarter = new Circle(radiusOfQuarter);
//Determine the area of the dollar bill.
Rectangle dollar = new Rectangle(lengDollar,widthDollar);
double totalAreaDollar = dollar.area();
double areaDollar = totalAreaDollar - (nickel.area() + dim+
e.area() + quarter.area());
//Display the results.
IO.println("The unobscured area is " + areaDollar + " squa+
re units.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac MoneyApp.java
$ java MoneyApp
The unobscured area is 14.115312288477789 square units.
$
*/
|
|
|