// DrJava saved history v2 /* Monday - Jan 17, 2005 */ /* first we reviewed the String manipulation */ String h = "Hi ! aren't you glad the weekend is over!"; /* when we tried to find a way to identify the position just */ /* after the exclamation mark - we first tried this */ h.indexOf("!"+1) /* but that was wrong because we need to first find the */ /* position of the exclamation mark and then move over one */ h /* this is the position of index of the position of the "!"*/ h.indexOf("!") /* remember that the index of the first position in a string is */ /* zero (i.e., 0) */ h.indexOf("!") + 1 /* This is how we would create a substring (or part of a string) */ /* of the string up to and including the "!" */ /* so we specify the start position 0, and the end position */ String i = h.substring(0, h.indexOf("!")+1) i /* now we want to take the remainder of the hi string starting */ /* with "aren't" - we can just start where "aren't" starts */ /* and take the remainder of the string. If you look at the */ /* String API documentation - this is the second form of the */ /* substring method. */ h = h.substring(h.indexOf("aren")) /* now we create a Book object using our new Book class */ /* but first we must pass the constructor the date as a */ /* date object - so we must create a date object */ import java.util.Date; Date d = new Date(); Book b = new Book("A Time to Kill", "John Grisham", d); b.numBooks() /** always call a static method with the class name first */ Book.getBookCount() /* never call it with the object that you have created */ /* we modified our Book class several times and retried the */ /* methods. Specifically - we modified our toString method */ /* to better format the output of the string */ Date today = new Date() today import java.util.Date; Date d = new Date(); Book b = new Book("A Time to Kill", "John Grisham", d); b.toString() import java.util.Date; Date d = new Date(); Book b = new Book("A Time to Kill", "John Grisham", d); b.toString() import java.util.Date; Date d = new Date(); Book b = new Book("A Time to Kill", "John Grisham", d); b.toString() /* rather than having to retype code every time you want */ /* to test a module - wouldn't it be nice to have a program */ /* that tests our program. We will be creating test programs */ /* next lesson. Stay tuned */