Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
package assignment1; import java.util.List; public class BasicDocument extends Document { public BasicDocument(String text) { super(text); } /** * Get the number of words in the document. * A "word" is defined as a contiguous string of alphabetic characters * i.e. any upper or lower case characters a-z or A-Z. This method completely * ignores numbers when you count words, and assumes that the document does not have * any strings that combine numbers and letters. * * Check the examples in the main method below for more information. * * This method should process the entire text string each time it is called. * * @return The number of words in the document. */ @Override public int getNumWords() { //TODO: Implement this method in week 2 according to the comments above. // See the Module 2 support videos if you need help. List<String> numberWord = getTokens("[a-zA-Z]+"); return numberWord.size(); } /** * Get the number of sentences in the document. * Sentences are defined as contiguous strings of characters ending in an * end of sentence punctuation (. ! or ?) or the last contiguous set of * characters in the document, even if they don't end with a punctuation mark. * * Check the examples in the main method below for more information. * * This method should process the entire text string each time it is called. * * @return The number of sentences in the document. */ @Override public int getNumSentences() { //TODO: Implement this method. See the Module 2 support videos // if you need help. List<String> numberWord = getTokens("[^.!?]+"); return numberWord.size(); } /** * Get the total number of syllables in the document (the stored text). * To count the number of syllables in a word, it uses the following rules: * Each contiguous sequence of one or more vowels is a syllable, * with the following exception: a lone "e" at the end of a word * is not considered a syllable unless the word has no other syllables. * You should consider y a vowel. * * Check the examples in the main method below for more information. * * This method should process the entire text string each time it is called. * * @return The number of syllables in the document. */ @Override public int getNumSyllables() { //TODO: Implement this method in week 2. See the Module 2 support videos // if you need help. And note that there is no need to use a regular // expression for the syllable counting. We recommend you implement // the helper function countSyllables in Document.java using a loop, // and then call it here on each word. List<String> tokens = getTokens("[a-zA-Z]+"); int totalSyllables = 0; for (String x : tokens) { totalSyllables = totalSyllables + countSyllables(x); } return totalSyllables; } /* The main method for testing this class. * You are encouraged to add your own tests. */ public static void main(String[] args) { testCase(new BasicDocument("This is a test. How many??? " + "Senteeeeeeeeeences are here... there should be 5! Right?"), 16, 13, 5); testCase(new BasicDocument(""), 0, 0, 0); testCase(new BasicDocument("sentence, with, lots, of, commas.! " + "(And some poaren)). The output is: 7.5."), 15, 11, 4); testCase(new BasicDocument("many??? Senteeeeeeeeeences are"), 6, 3, 2); testCase(new BasicDocument("Here is a series of test sentences. Your program should " + "find 3 sentences, 33 words, and 49 syllables. Not every word will have " + "the correct amount of syllables (example, for example), " + "but most of them will."), 49, 33, 3); testCase(new BasicDocument("Segue"), 2, 1, 1); testCase(new BasicDocument("Sentence"), 2, 1, 1); testCase(new BasicDocument("Sentences?!"), 3, 1, 1); testCase(new BasicDocument("Lorem ipsum dolor sit amet, qui ex choro quodsi moderatius, nam dolores explicari forensibus ad."), 32, 15, 1); } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत