Non-void methods

Chapter: Non-void methods

(also known as functions in Alice and by some programmers).

For the next exercise I want you to write a method that returns a boolean value to be displayed by the caller. Your method will be called by Ex2.java to confront the user with a JFrame that looks like this:

If I type my name in the data box and click the button, the output is produced:

Had I typed my name with no upper case letters, the output field would read "Has Capitals: false".


Exercise 2

Write a public boolean method named checkForCapitals that takes a String argument and returns true if the String has at least one upper case letter and false otherwise. Write your method and incorporate it into Ex2.java. You will need to write about three lines of code. Do not change any of the existing code. The resulting file should compile and run as advertised. Hint: Look at the documentation for the String class and use two of the methods given there and a logical operator to solve this problem neatly.


rhyspj@gwu.edu