image

TCS ILP java Exercise 1

Hello friends,
Here i am going to publish you the TCS's(Tata Consultancy Services) ILP( Initial Learners Program ) java stream, JAVA Exercise 1.

If you are interested please solve the problems and publish in the site or email them to This email address is being protected from spambots. You need JavaScript enabled to view it. it will help our friends.

Exercise 1: How to design programs

Design the following programs by developing the Contract, Purpose, Header, Example and Algorithm. Validate your algorithm by doing a dry run.

1. Maximum of 3 numbers

Find the maximum of three numbers

2. Maximum of a series of numbers

Find the maximum of a series of numbers

3. Sum of squares of two numbers

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

4. 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.

5. 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.

6. 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.

7. 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.

8. 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.

9. 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.

10. 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.

11. Interest calculation

Develop the program interest. Like interest-rate, it consumes a deposit amount. Instead of the rate, it produces the actual amount of interest that the money earns in a year. The bank pays a flat 4% for deposits of up to $1,000, a flat 4.5% per year for deposits of up to $5,000, and a flat 5% for deposits of more than Rs.5, 000.

12. Tax

Develop the program tax, which consumes the gross pay and produces the amount of tax owed. For a gross pay of $240 or less, the tax is 0%; for over Rs. 240 and Rs. 480 or less, the tax rate is 15%; and for any pay over $480, the tax rate is 28%. Also develop netpay. The program determines the net pay of an employee from the number of hours worked. The net pay is the gross pay minus the tax. Assume the hourly pay rate is Rs.12. Remember to develop auxiliary programs when a definition becomes too large or too complex to manage.

13. Pay Back

Some credit card companies pay back a small portion of the charges a customer makes over a year. One company returns 1. .25% for the first Rs500 of charges, 2. .50% for the next Rs1000 (that is, the portion between Rs500 and Rs1500), 3. .75% for the next Rs1000 (that is, the portion between Rs1500 and Rs2500), 4. and 1.0% for everything above Rs2500. Thus, a customer who charges Rs. 400 a year receives Rs.1.00, which is 0.25 • 1/100 • 400, and one who charges Rs1, 400 a year receives Rs. 5.75, which is 1.25 = 0.25 • 1/100 • 500 for the first Rs. 500 and 0.50 • 1/100 • 900 = 4.50 for the next Rs. 900. Determine by hand the pay-backs for a customer who charged Rs. 2,000 and one who charged Rs2600. Define the program pay-back, which consumes a charge amount and computes the corresponding pay-back amount.

14. 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).

15. Area of a rectangle

Write the contract, purpose, and header for a program that computes the area of a rectangle given its length and width. Write three examples for the behavior of this program.

16. Distance traveled

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.

17. Interest rate

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.

18. Tiles needed

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.

19. Mean of exam scores

Develop a program to return the mean of 5 exam scores.

20. Perimeter of a square

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

21. Distance

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.

22. 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.

Download the question in a pdf file : http://java.sourcecode4u.com/uploads/Exercise1-HTDP.pdf

меня зовут эрл