



|
|
My Intro to Object-Oriented Programming
|
Programming Challenge Archive
Programming Assignment # 2
Money
|
|
|
Three coins (a quarter, a nickel, and a dime) are placed flat on a dollar bill in such a way that they do not overlap and do not overhang the dollar bill. Find the area of the dollar bill not obscured by the coins.
JavaApplication - Programming Assignment # 2 --
Money
// General Information
// ---------------------------------------------------
// File: MoneyApp.java
// Type: java application file
// Date: Mon Sep 25, 2000
// Name: Jeffrey R Norkoli
// Line: Find the unobscured area on a dollar bill.
// Application Description
// ---------------------------------------------------
/*
Three coins (a quarter, a nickel, and a dime) are
placed flat on a dollar bill in such a way that
they do not overlap and do not overhang the
dollar bill. Find the area of the dollar bill
not obscured by the coins.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class MoneyApp
{
static public void main (String args[])
{
// By observation, record the diameter of
// the coins and the dimensions of the
// dollar bill. All measurements in inches.
double diameterQuarter = 15.0/16.0;
double diameterNickel = 13.5/16.0;
double diameterDime = 11.5/16.0;
double lengthDollar = 6.0 + 1.0/8.0;
double widthDollar = 2.0 + 5.0/8.0;
// Model the coins.
double radiusQuarter = diameterQuarter/2.0;
double radiusNickel = diameterNickel/2.0;
double radiusDime = diameterDime/2.0;
Circle quarter = new Circle(radiusQuarter);
Circle nickel = new Circle(radiusNickel);
Circle dime = new Circle(radiusDime);
// Compute the surface area of the coins.
double saCoins = quarter.area() + nickel.area()
+ dime.area();
// Model the dollar bill.
Rectangle dollarBill = new
Rectangle(lengthDollar,widthDollar);
// Compute the surface area of the dollar bill.
double saDollarBill = dollarBill.area();
// Compute the surface area of the dollar
// bill unobscured.
double areaUnobscured = saDollarBill - saCoins;
// Display result.
IO.println ("The unobscured area is " +
areaUnobscured + " square inches.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac MoneyApp.java
$ java MoneyApp
The unobscured area is 14.422959729871394 square
inches.
$
*/
|
|
|