Solutions for the Sample Exam 3 - CS 303e 1. this 2. (s.length() == 1) && Character.isLetter(s.charAt(0)) 3. we didn't cover command line arguments. 4. s instanceof Square 5. str.indexOf("great") >= 0 6. A method name is overloaded if there are two or more methods which have that same name but different parameter lists. 7. Random gen = new Random(); int ranNum = gen.nextInt(myStrings.length); System.out.print(myStrings[ranNum]); 8. Scanner scan = new Scanner(System.in); int[] nums = new int[10]; for(int i = 0; i < 10; i++) nums[i] = scan.nextInt(); 9. We went over this example in class. 10. public int[] workStrings(String[] stringArray) { int[] arr = new int[2]; int countLower = 0; int countDigit = 0; for(int i = 0; i < stringArray.length; i++) { char first = stringArray[i].charAt(0); if(Character.isLetter(first) && Character.isLowerCase(first)) countLower++; char last = stringArray[i].charAt(stringArray[i].length-1); if(Character.isDigit(last)) countDigit++; } arr[0] = countLower; arr[1] = countDigit; return arr; } 11. public class DictionaryEntry { private String word; private String definition; public String getWord() { return word; } public String getDefinition() { return definition; } public void setWord(String newWord) { word = newWord; } public void setDefinition(String def) { definition = def; } public DictionaryEntry(String word, String definition) { this.word = word; this.definition = definition; } public String toString() { return "DictionaryEntry[word = " + word + ", definition = " + definition + "]"; } public Object clone() { DictionaryEntry newEn = new DictionaryEntry(word, definition); return newEn; } public boolean equals(Object other) { if(other == null) return false; if(other instanceof DictionaryEntry) { DictionaryEntry d = (DictionaryEntry) other; return (word.equals(d.word) && definition.equalsIgnoreCase(d.definition)); } return false; } }