Docsity

Practice Test 2 Solutions | Algorithmic Design I | CSCE 145, Exams of Computer Science

Partial preview of the text

Download Practice Test 2 Solutions | Algorithmic Design I | CSCE 145 and more Exams Computer Science in PDF only on Docsity!

CSCE 145 Practice Test 2 Solutions

[1]

Robin Starfire BeastBoy [2] 40 36 32 28 24 To infinity 10 11 12 11 12 12 and beyond! [3] 1-Penn 2-Penn 3-Teller 4-10000. 5-9000. 6-10000. 7-10000. 8-400. [4]

[5]

public interface ISimpleNumber { public boolean isEven(); public int multiplyByTwo(); } public class SimpleNumber implements ISimpleNumber { private int value; public SimpleNumber( int v){ this .value = v; } public boolean isEven() { return this .value % 2 == 0; } public int multiplyByTwo() { this .value *= 2; return this .value; } } [6] public static String fullStateName(String abbrev){ int abbrevIndex, beginIndex, endIndex; String abbrevPlsFirst, nextAbbrev, nextAbbrevPlsFirst; abbrevIndex = acro.indexOf(abbrev); String subAcro = acro; while (abbrevIndex % 2 != 0){ subAcro = subAcro.substring(abbrevIndex + 1); abbrevIndex += subAcro.indexOf(abbrev) + 1; } abbrevPlsFirst = abbrev + abbrev.charAt(0); beginIndex = acroStates.indexOf(abbrevPlsFirst) + 2; if (abbrevIndex < acro.length() - 2){ nextAbbrev = acro.substring(abbrevIndex + 2, abbrevIndex + 4); nextAbbrevPlsFirst = nextAbbrev + nextAbbrev.charAt(0); endIndex = acroStates.indexOf(nextAbbrevPlsFirst); return acroStates.substring(beginIndex, endIndex); } else { return acroStates.substring(beginIndex); } }