# Stanford CS 106A - Study Notes (2 pages)

Previewing page 1 of 2 page document
View Full Document

## Study Notes

Previewing page 1 of actual document.

View Full Document
View Full Document

## Study Notes

154 views

Pages:
2
School:
Stanford University
Course:
Cs 106a - Programming Methodology
##### Programming Methodology Documents
• 6 pages

• 11 pages

• 3 pages

• 4 pages

• 4 pages

• 5 pages

• 23 pages

• 6 pages

• 4 pages

• 4 pages

• 5 pages

• 2 pages

• 3 pages

• 19 pages

• 4 pages

• 4 pages

• 4 pages

• 4 pages

• 4 pages

• 2 pages

• 15 pages

• 8 pages

• 26 pages

• 2 pages

• 10 pages

• 2 pages

• 28 pages

• 3 pages

• 6 pages

• 9 pages

• 15 pages

• 4 pages

• 3 pages

• 21 pages

• 14 pages

• 4 pages

• 2 pages

• 12 pages

• 16 pages

• 30 pages

• 2 pages

• 4 pages

• 3 pages

• 4 pages

• 2 pages

• 25 pages

• 20 pages

• 2 pages

• 2 pages

• 3 pages

• 2 pages

• 28 pages

• 11 pages

Unformatted text preview:

Eric Roberts CS 106A Handout 32 February 1 2010 Section Handout 4 String Processing 1 Scrabble scoring Chapter 8 exercise 5 page 286 In most word games each letter in a word is scored according to its point value which is inversely proportional to its frequency in English words In Scrabble the points are allocated as follows Points Letters 1 A E I L N O R S T U 2 D G 3 B C M P 4 F H V W Y 5 K 8 J X 10 Q Z For example the Scrabble word FARM is worth 9 points 4 for the F 1 each for the A and the R and 3 for the M Write a ConsoleProgram that reads in words and prints out their score in Scrabble not counting any of the other bonuses that occur in the game You should ignore any characters other than uppercase letters in computing the score In particular lowercase letters are assumed to represent blank tiles which can stand for any letter but which have a score of 0 2 Adding commas to numeric strings Chapter 8 exercise 13 page 290 When large numbers are written out on paper it is traditional at least in the United States to use commas to separate the digits into groups of three For example the number one million is usually written in the following form 1 000 000 To make it easier for programmers to display numbers in this fashion implement a method private String addCommasToNumericString String digits that takes a string of decimal digits representing a number and returns the string formed by inserting commas at every third position starting on the right For example if you were to execute the main program public void run while true String digits readLine Enter a numeric string if digits length 0 break println addCommasToNumericString digits your implementation of the addCommasToNumericString method should be able to produce the following sample run 2 AddCommas Enter a number 17 Enter a number 1 001 Enter a number 12 345 678 Enter a number 999 999 999 Enter a number 17 1001 12345678 999999999 3 Deleting characters from a string Write a method public String removeAllOccurrences String str char ch that removes all occurrences of the character ch from the string str For example your method should return the values shown removeAllOccurrences This is a test t returns removeAllOccurrences Summer is here e returns removeAllOccurrences 0 returns This is a es Summr is hr 0

View Full Document

Unlocking...