Anda di halaman 1dari 3

Exercise 2: Java Basics 1.

Sum of squares of two numbers


What is the difference between sum of the squares and the square of the sums of two numbers?

2. Tax calculation
Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program tax, which determines the tax on the gross pay. Also define netpay. The program determines the net pay of an employee from the number of hours worked. Assume an hourly rate of $12.

3. Theatre profit
An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program total-profit. It consumes the number of attendees (of a show) and produces how much income the attendees produce.

4. Metric conversion
The United States uses the English system of (length) measurements. The rest of the world uses the metric system. So, people who travel abroad and companies that trade with foreign partners often need to convert English measurements to metric ones and vice versa. Here is a table that shows the six major units of length measurements of the English system: Develop the programs inches->cm, feet->inches, yards->feet, rods->yards, furlongs->rods, and miles->furlongs. Then develop the programs feet->cm, yards->cm, rods->inches, and miles->feet. Develop the programs inches->cm, feet->inches, yards->feet, rods->yards, furlongs->rods, and miles->furlongs. Then develop the programs feet->cm, yards->cm, rods->inches, and miles->feet.

5. Volume of cylinder

Develop the program volume-cylinder. It consumes the radius of a cylinders base disk and its height; it computes the volume of the cylinder.

6. Area of a cylinder
Develop area-cylinder. The program consumes the radius of the cylinders base disk and its height. Its result is the surface area of the cylinder.

7. Area of a pipe
Develop the program area-pipe. It computes the surface area of a pipe, which is an open cylinder. The program consumes three values: the pipes inner radius, its length, and the thickness of its wall.

8. Height calculation
Develop the program height, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g t in t time units and a height of 1/2 * v * t where v is the speed at t.

9. Distance calculation
Develop a program that computes the distance a boat travels across a river, given the width of the river, the boats speed perpendicular to the river, and the rivers speed. Speed is distance/time, and the Pythagorean Theorem is c2 = a2 + b2.

10.

Balance calculation

Develop a program that when given an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional deposits or withdrawals are made and that a month is 1/12 of a year. Total interest is the product of the principal, the annual interest rate expressed as a decimal, and the number of years.

11.

Estimation

Develop a program that when given the length and width of a rectangular floor and the edge length of a square tile will compute the whole number of tiles needed to cover the floor completely.

12.

Area of a regular polygon

Develop a program that computes the area of a regular polygon given the length of one side and the number of sides. If n is the number of sides and s is the length of a side, the area of a regular polygon is equal to 1/4 * n * s2 * 1/(tan PI/n).

13.

Mean of exam scores

Develop a program to return the mean of 5 exam scores

14.

Perimeter of a square

Develop a program that when given the area of a square will calculate its perimeter.

15.

Distance calculation

Drop a rubber ball from a height h. Each time it hits the ground, the ball bounces up to 2/3 of the height it dropped. Develop a program that computes how far the ball travels by the time it hits the ground for the third time? Hint: try 36[in] for the initial height.

16.

Total inches

Develop the program, total-inches. The program consumes a length represented by two numbers: the first a number of feet, and the second a number of inches. The program produces the total length in inches.

Anda mungkin juga menyukai