Stanford CS 106A - Study Notes (2 pages)

Previewing page 1 of 2 page document View the full content.
View Full Document

Study Notes



Previewing page 1 of actual document.

View the full content.
View Full Document
View Full Document

Study Notes

154 views


Pages:
2
School:
Stanford University
Course:
Cs 106a - Programming Methodology
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

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?