Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Programming 3
- Lab 2
- 09.10.2012: First steps in Java.
- Theme: Arrays.
- On today's labs you will be writing a program, which will be working with a long sentence (example: a poem). Functionalities, you will be asked to implement include: dividing a sentence into words, sorting words in alphabetical order, counting occurences of words in the sentence, generating a sentence (a not necessary meaningful set of words).
- Declare following variable:
- String sentence = "How are you, are you ok? If not please say something. I would like to ask you how was your day. What are your plans for the rest of the week? Any good plans for the weekend? Just-in-case if we don't see each other: have a joyful day!";
- It is your sentence, with which you will be working today.
- Assume that a word is a substring of a sentence, that may be limited by:
- - blank space (" ") - please note, that there might be more than one white space,
- - a punctuation mark (for example: ".", ",","!" and so on).
- Assume that a word is a substring containing letters only. Hyphenated word is one word, numbers are always ommited.
- Subtask 1: Divide variable "sentence" into separate words. Print each word out in separate line on the console, in the order, in which they are in the sentence. (4 pts)
- Subtask 2: Count words occurrences. On the console print each word and a number of how many times it was repeated in the sentence. (4 pts)
- Subtask 3: Sort words in alphabethical ascending order. Words, that occur more than once, should be printed only once. Print sorted words on the console. (5 pts)
- All tasks require manipulations with Strings and arrays of characters. Here is the list of inbuilt helpers:
- http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html
- http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Character.html
- How your work will be graded?
- Subtask 1: Dividing sentence into words: 4 pts.
- Subtask 2: Counting occurrences of words in the sentence: 4 pts.
- Subtask 3: Sorting: 5 pts.
- Compilation errors, style: 2 pt.
- Together: 15 pts.
- 100% = 10 pts, so you don't need to implement all of functionalities to get full score!
Advertisement
Add Comment
Please, Sign In to add comment