/*****************************
Math Problems
--------------
Computers were invented to do calculations - e.g. to COMPUTE answers.
The first digital computers were built in the 1940's, to be used
by the military. The world's first PROGRAMMABLE digital computer,
Colossus, was built in England in 1944 to decipher the Germans' Enigma code.
The American Eniac computer was built and completed at the end World War II.
Eniac was used for 8 years for military applications, including designing the
hydrogen bomb.
Despite occasional round-off and overflow errors, computers are ideal
for doing large, complex mathematical calculations. As in mathematics,
we find VARIABLES quite useful in computer programs. Variables have
several benefits:
(1) The same value can be used over an over again just by writing
the name of the variable, rather than typing the number
over and over again
(2) Variables FORCE a specific TYPE for a value, thus avoiding
some of annoying arithmetic errors
(3) A variable can be CHANGED, so a whole list of values can be
calculated by a single program
Here is a sample program that calculates the area of several circles.
******************************/
import java.awt.*;
public class Circles
{
public static void main(String[] args)
{
double pi = 3.1415926;
double r = 10;
System.out.println("Circles");
System.out.println("------------------");
System.out.println("Radius = " + r);
System.out.println("Area = " + pi*r*r );
System.out.println("------------------");
r = 15;
System.out.println("Radius = " + r);
System.out.println("Area = " + pi*r*r );
System.out.println("------------------");
r = 20;
System.out.println("Radius = " + r);
System.out.println("Area = " + pi*r*r );
System.out.println("------------------");
}
}
/***************************************************
(1) By using the Circles program and changing the radius to
various values, find a circle with area = 1000.
Your answer for the radius should be to the nearest 0.01.
(2) Make a Rectangles program that calculates the area
of a rectangle. It needs variables for Width and Height.
The output should look like this:
Width =
1
Height = 2
Area = 2
Width = 3
Height
= 4
Area
= 12
Width = 5
Height
= 6
Area = 30
Width = 7
Height
= 8
Area = 56
Width = 9
Height
= 10
Area = 90
It must COMPUTE the area each time by multiplying (Width * Height).
(3) Make a progam to calculate values for the function y = 2*x / (x+1)
(a) It should have an output that looks like this:
X =
1
Y =
1
X =
2
Y = 1.333...
X =
3
Y = 1.5
...
...
X =
9
Y
=
1.8
X =
10
Y
= 1.9181...
(b) Change the X values to count 1.1, 1.2, 1.3, ... 1.9
(c) Find the X value that produces Y = 1.25
****************************************************/