The exercises here are taken from my forthcoming book
The Java Developer's Resource.
In one line, how would you find the minimum of three values? of four? of five?
Write the Java equivalent of the following formulas:
Area of a square: A = s2
Area of a circle: A = pir2
Circumference of a circle: C = 2pir
Positive root of the quadratic equation *: *
Slope of the line between two points: *
Sales tax in New York City is 8.25%. Write a program that accepts a price on the command line and prints out the appropriate tax and total purchase price.
Modify the sales tax program to accept an arbitrary number of prices, total them, calculate the sales tax and print the total amount.
Write a program that reads two numbers from the command line, the number of hours worked by an employee and their base pay rate. Then output the total pay due.
Modify the previous program to meet the U.S. Dept. of Labor's requirement for time and a half pay for hours over forty worked in a given week.
Add warning messages to the payroll program if the pay rate is less than the minimum wage ($4.35 an hour as of mid-1996) or if the employee worked more than the number of hours in a week.
There are exactly 2.54 centimeters to an inch. Write a program that takes a number of inches from the command line and converts it to centimeters.
Write the inverse program that reads a number of centimeters from the command line and converts it to inches.
There are 454 grams in a pound and 1000 grams in a kilogram. Write programs that convert pounds to kilograms and kilograms to pounds. Read the number to be converted from the command line. Can you make this one program instead of two?
The equivalent resistance of resistors connected in series is calculated by adding the resistances of the individual resistors. Write a program that accepts a series of resistances from the command line and outputs the equivalent resistance.
The formula for resistors connected in parallel is a little more complex. Given two resistors with resistances R1 and R2 connected in parallel the equivalent resistance is given by the inverse of the sum of the inverses, i.e.
If there are more than two resistors you continue to invert the sum of their inverses; e.g. for four resistors you have:
Write a program that calculates the resistance of a a group of resistors arranged in parallel.