hts.StevenWood.com

[ Last Page ]

Review Questions

  1. Answer each of the following:  Solutions
    1. Program modules in Java are called _____ and _____.
    2. A method is invoked with a  _____.
    3. A variable known only within the method in which it is defined is called a  _____.
    4. The _____ statement in a called method can be used to pass the value of an expression back to the calling method.
    5. The keyword _____ is used in a method header to indicate that a method does not return a value.
    6. The _____ of an identifier is the portion of the program in which the identifier can be used.
    7. The _____ method is used to produce random numbers.
    8. The _____ qualifier is used to declare read-only variables.
  2. Write an application that will display the following using the Math library methods:

    Solutions

    What do you think the answer will be before running the application?
    1. The absolute value of -34.5
    2. The absolute value of 0.0
    3. The absolute value of 45.3
    4. The cosine of 0.0 radians
    5. The cosine of 1.0 radians
    6. The ceiling of 9.5
    7. The ceiling of -12.4
    8. The floor of 8.4
    9. The floor of -34.4
    10. The larger of -34.4 and -12.4
    11. The smaller of 8.4 and 9.5
    12. The value of 45
    13. The value of 40.5
    14. The value of 4-5
    15. A random decimal number from 0 to 1
    16. Round 5.6
    17. Round -5.6
    18. The sine of -1.0 radians
    19. The sine of 1.0 radians
    20. The square root of 10.
    21. The square root of 2560.5
    22. The tan of -1.0 radians
    23. The tan of 1.0 radians
    24. The number of radians in 45°
    25. The number of radians in 135°
  3. Find the error(s) in each of the following program segments and explain how the error can be corrected.  Solutions
    a.
    b.
    c.
    d.
    e.

     

  4. Give the method header for each of the following methods. Solutions
    1. Method hypotenuse which takes two double-precision, floating-point arguments side1 and side2 and returns a double-precision, floating-point result.
    2. Method smallest, which takes three integers, x, y, and z and returns an integer.
    3. Method instructions, which does not take any arguments and does not return a value.  Note: this type of method may be used to show instructions to the user.
    4. Method intToFloat, which takes an integer argument, number and returns a floating-point result.
  5. Write a complete Java application to find the volume of a sphere, Use a method to prompt the user for the double radius of a sphere. A method, sVolume, is used to calculate the volume. The application displays the volume with a concluding sentence. Solution
  6. Write a statement that assigns a random integer to the variable n in the following ranges.
    a.
    b.
    c.
    d.
  7. Write a single statement that will print a number at random from the set of numbers:
    6, 10, 14, 18, 22.
  8. a) Write a method named average that receives 2 integer numbers and returns the average of the two numbers.
    b) Write an application that makes use of the method average. Solution
  9. Complete the method described in 4a and use it in an application.
  10. Complete the method described in 4b and use it in an application.
  11. a) Write a String method named changeCase. It accepts a string and a character. The character is 'U' or 'u' or 'L' or 'l' (lower case L). If it is U or u then the returned string should be uppercase. If it is L or l then the returned string should be lowercase. Any other character should return the string unchanged.
    b) Write an application that makes use of the method in (a). Solution
  12.  

 

Source: Deitel, H.M. and Deitel P.J. Java: How to Program. 3rd ed. Upper Saddle River, New Jersey. Prentice Hall.1999. ISBN 0-13-012507-5, p 254-261. and others.

 
[Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+