Java Reference
In-Depth Information
8 Ohm's Law
Ohm's law relates the resistance of an electrical device, such as a portable heater,
to the electric current flowing through the device and the voltage applied to it.
The law uses the formula
I = V/R
where V is the voltage, measured in volts; R is the resistance, measured in ohms;
and I is the answer, the electrical current, measured in amps. Write an applet that
displays a welcome message, two Label prompts, and TextFields. One Label will
ask the user to input the voltage; the other Label will ask the user to input the
resistance of a device. The applet then will display the current. Remember that
because V and R will be entered as integers, the ActionListener will have to parse
the numbers into double values in order to perform the division.
9 Calculating the Circumference of a Circle
Your younger brother is studying beginning geometry. He has to calculate the
circumference of several different circles and would like to automate the process.
Write a stand-alone application for him that calculates the circumference of a
circle from the radius. The radius will be an integer value input from the key-
board. Create a method that will accept the integer and perform the calculation
using the formula, 2* pi *r — that is, 2 times the value of pi times the radius. Use
the value 3.14 or the Java variable, Math.PI, in your calculation.
10 Dollars and Cents
Write a program that will spell out the number of dollars and cents based on
user numeric input. For instance, if the user inputs 925, the program will print
out 9 dollars and 25 cents. For this program, you will use integer arithmetic and
will need to avoid floating point arithmetic. Review modular division and the
modular operator (%), as discussed in the chapter.
11 Currency Conversion
Because you are an outstanding student, a local civic organization has awarded
you a generous sum of money to pursue your education in England. You also
plan to do some sightseeing while you are in Europe. The award money is in U.S.
dollars, and you want to know how that will convert to the British pound, the
euro, and the Russian ruble. Use the concepts and techniques presented in this
chapter to create an application that will accept the U.S. dollar amount, convert
the U.S. dollar amount, and display the British pound, euro, and Russian ruble
equivalents. Use the Web, a newspaper, or a local financial institution to obtain
the conversion rates.
J ava 2
v 5 . 0
Java 2
12 Using the Sun Microsystems Java Documentation
v 5 . 0
Use the Java API (http://java.sun.com/j2se/1.5.0/docs/api) to find documentation
on Java packages. In particular, search the site for methods in the Math class.
Make a list of 8 methods, and describe their arguments and what they return.
Search WWH ::




Custom Search