siloMehran Sahami Handout #30
CS 106A October 29, 2012 Section Handout #5: Files, ArrayLists, and Class
Portions of this handout by Eric Roberts
1. Word Count
Write a program WordCount that reads a file and reports how many lines, words, and characters appear in it. Suppo, for example, that the contains the following passage from Shakespeare’s King Lear:
Given this file, your program should be able to generate the following sample run:
For the purpos of this program, a word consists of a concutive quence of letters and/or digits, which you can test using the static method Character.isLetterOrDigit. Also, you should not count the characters that mark the end of a line, which will have different values depending on the type of computer.
2. How Unique!
大专生如何考研Write a program that asks the ur for a list of names (one per line) until the ur enters a blank line (i.e., just hits return when asked for a name). At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the ur entered the name in the program. You may find that using an ArrayList to keep track of the names entered by ur may greatly simplify this problem.
A sample run of this program is shown below.
3. A Christmas Carol
Using the Student class from Chapter 6 as an example, write a class definition for a class called Employee, which keeps track of the following information:
•The name of the employee
•The employee’s nine-digit tax id number
•The employee’s job title
• A flag indicating whether the employee is still active
•The employee’s annual salary
The first two fields should be t as part of the constructor, and it should not be possible for the client to change the values after that. For the other fields, your class definition should provide getters and tters that manipulate tho fields. Once you have made this definition, write the code necessary to initialize the following Employee objects:四级考试需要带什么
yageoWhat would you need to do to double Bob Cratchit’s salary?
aaa培训
4. Histogramsbolt是什么意思
whatever什么意思Write a program that reads a list of exam scores from the (which contains one score per line) and then displays a histogram of tho numbers, divided into the ranges 0–9, 10–19, 20–29, and so forth, up to the range
洗衣服务 contains the data shown in the right margin, your program should then be able to generate a histogram that looks as much as possible like the following sample run:
5. Happy Holloween
For the program below, trace through its execution by hand to show what output is produced when it runs.碎纸机英文>生活大爆炸第一季下载地址