Assignment No.4

  1. (Textbook Chapter 3 Exercise 17) Write a method called padString that accepts two parameters: a String and an integer representing a length. The method should pad the parameter string with sapces until its length is equal to the given length. For example, padString("hello", 8) should return "helloi i i ". (This sort of method is useful when trying to print output that lines up horizontally.) If the string's length is already at least as long as the length parameter, your method should return the original string. For example, padString("congratulations", 10) should return "congratulations".

  2. (Textbook Chapter 3 Exercise 20) Write a method called inputBirthday that accepts a Scanner for the console as a parameter and prompts the user to enter a month, day, and year of birth, then prints the birthdate in a suitable format. Here is an example dialog with the user:

    On what day of the month were you born? 8
    What is the name of the month in which you were born? May
    During what year were you born? 1981
    You were born on May 8, 1981. You're mighty old!

Go back to the assignment list page.