KFUPM, ICS Department 2/2 Fall 2007 (Term 071)

KFUPM, ICS Department 2/2 Fall 2007 (Term 071)

<p> King Fahd University of Petroleum & Minerals ICS102: Introduction to Computing</p><p>Information and Computer Science Department Fall 2007 (Term 071)</p><p>Lab04: Java Strings</p><p>Objectives Designing and implementing Java programs that deal with: 1. String Class Objects. 2. String Concatenation (+). 3. String Class Methods (length, equals, equalsIgnoreCase, toLowerCase, toUpperCase, trim, charAt, substring, indexOf, lastIndexOf, compareTo, compareToIgnoreCase). Refer to the String class (page 1022) on Appendix 4 of the book, or to the JDKv1.5 Documentation online or offline for more methods belonging to the String class. 4. String Indices 5. Escape Sequences (\”, \’, \\, \n, \r, \t). 6. The Imputable Characteristic of the String Object.</p><p>Example The following example generates a password for a student using his initials and age. (Note: do not use this for your actual passwords). /*</p><p>* generates a password for a student using his initials and age</p><p>*/</p><p> public class PasswordMaker {</p><p> public static void main(String[] args) {</p><p>String firstName = "Amr";</p><p>String middleName = "Ahmed";</p><p>String lastName = "Al-Ghamdi";</p><p> int age = 20; KFUPM, ICS Department 2/3 Fall 2007 (Term 071) ICS102: Introduction to Computing Lab04: Java Strings</p><p>// extract initials</p><p>String initials = firstName.substring(0,1) +</p><p> middleName.substring(0,1) +</p><p> lastName.substring(0,1);</p><p>// append age after changing the initials to lower case</p><p>String password = initials.toLowerCase() + age;</p><p>System.out.println("Your Password = " + password);</p><p>}</p><p>}</p><p>Exercises</p><p>Exercise #01: (StringWelcome.java)</p><p>Design and implement a Java program that will do the following operations to this string “Welcome! This is ICS102 Course”:  convert all alphabets to capital letters and print out the result;  convert all alphabets to lower-case letters and print out the result; and  print out the length of the string.  print out the index of Course.</p><p>Exercise #02: (PasswordMaker2.java)</p><p>Modify the example shown above in such a way that instead of taking initials of the name, the new program will take the middle letter from the first, middle and last name. The obtained letters will be concatenated along with age which is multiply by 100. NOTE: your program should work for any names NOT ONLY those names specified in the example.</p><p>Exercise #03: (FamilyName.java)</p><p>We have two student names Ali Al-Ali and Ahmed Al-Ahmed. Design and implement a Java program that will exchange the last names of the two students in such a way that the new names are going to be Ali Al-Ahmed and Ahmed Al-Ali. NOTE: your program should work for any names NOT ONLY these given names in the exercise. KFUPM, ICS Department 3/3 Fall 2007 (Term 071) ICS102: Introduction to Computing Lab04: Java Strings Exercise #04: (Swap.java)</p><p>We have the student name ali al-ali. Desing and implement a Java program that will change the first letter with the last letter and it will change the last letter with the first letter and the new name is going to be ili al-ala. NOTE: your program should work for any name NOT ONLY this given name in the exercise.</p><p>Exercise #05: (Optional) (Replace.java)</p><p>Assume you have the following string: “This is ICS102 Lab”. Write a program that searches for ICS102 and replaces it with COE-202.</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us