Homework 6
Download
1 / 18

Homework 6 - PowerPoint PPT Presentation


  • 193 Views
  • Updated On :

Homework 6. Sun., 10/12. ( MT sections ). Due . about midnight. Mon., 10/13. ( WTh sections ). Problems. http://www.cs.hmc.edu/courses/2003/fall/cs5/week_06/homework.html. CS 5 website. http://www.cs.hmc.edu/courses/2003/fall/cs5/. Submission problems? Grading concerns ?.

Related searches for Homework 6

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Homework 6' - KeelyKia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Slide1 l.jpg

Homework 6

Sun., 10/12

( MT sections )

  • Due

about midnight

Mon., 10/13

( WTh sections )

  • Problems

http://www.cs.hmc.edu/courses/2003/fall/cs5/week_06/homework.html

  • CS 5 website

http://www.cs.hmc.edu/courses/2003/fall/cs5/

  • Submission problems? Grading concerns ?

let me know!

email me at dodds@cs.hmc.edu



Slide3 l.jpg

Available in the LAC Lab (Linde Activities Center)

Available in Parsons PC Labs (the CIS classrooms)

You may also seek out tutors away from the labs, by phone, in the dorms, etc.


Slide4 l.jpg

HW 6

  • Problem 1: The Mudder’s Meander

  • Problem 2: throwing darts at pi

(0.5)

You’ll need to write (and use) the method:

1.0

(0.5,0.5)

public static boolean throwAndCheckDart()

1.0

  • Problem 3: Flesch readability score

You’ll need to write (and use) 2 methods:

public static int numSyllables(String word)

public static boolean isVowel(char c)


Slide5 l.jpg

Computers evaluating reading?

Problem: to determine the readability of text

The cow is of the bovine ilk . One end is moo the other milk !

very readable

  • 14 words (don’t count the punctuation marks!)

  • 2 sentences (do count the punctuation marks!)

  • 16 syllables (“bovine” and “other” are the two-syllable words)

206.835 - 84.6*(syllables/word) - 1.015*(words/sentence)

206.835 - 84.6*(16/14) - 1.015*(14/2)

watch out!

~ 103


Slide6 l.jpg

Handling input

code

user input

while (true)

{

String w = H.nw();

if (w.equals(“END”))

break;

// do all processing here

}

The cow is of the bovine ilk . One end is moo the other milk ! END

punctuation will ALWAYS be separated from text

H.nw() handles all whitespace as word separators. Newlines are not different than spaces.

the text will end with the word “END” (and it will appear nowhere else!)

H.nw() will return each space-separated String as a word.

counting words, sentences?


Slide7 l.jpg

main

public static void main(String[] args)

{

while (true)

{

String w = H.nw();

if (w.equals(“END”))

break;

}

}


Slide8 l.jpg

// get each word in turn - using nextWord()

// stop when END is seen

// Stage 1: simply count up the # of Strings

and print out the total @ the end


Slide9 l.jpg

// distinguish REAL words from “.” “!” “?”

// Stage 2: count up the # of words + sents.

print out both totals @ the end


Slide10 l.jpg

// count the syllables of each word

// Stage 3: take in SINGLE words and print

the number of syllables in each


Slide11 l.jpg

Syllables

What’s a syllable ?

aeiouyAEIOUY

Basically, a syllable is a cluster of 1 or more vowels in a word.

vowel

emerge

the

Put another way, a syllable is

  • any vowel that starts a word, plus

  • any vowel that follows a consonant

except

  • a lone e at the end of the word

But above all, every word must count as at least 1 syllable!


Slide12 l.jpg

Helpful Methods

public static int numSyllables(String word)

simile

Wrapped

bungee

Yes

beautifully

Sequoia

What are some (other) English words for which this syllable algorithm is incorrect?


Slide13 l.jpg

Checking for vowels

public static boolean isVowel(char c)

How would this get used to check for a vowel?

How would this get used to check for a consonant?


Slide14 l.jpg

Counting Syllables

public static int numSyllables(String word)


Slide15 l.jpg

Easy as p

Visualize:


Slide16 l.jpg

0. The user specifies how many darts to throw.

// get numDarts from user

// use a for loop to throw that many darts

// keep track of how many hits we get

// after all the darts, estimate p


Slide17 l.jpg

1. The user specifies how accurately to estimate pi.

// get tolerance from user

// start throwing darts

// keep track of # of hits and # of darts!

// estimate p each time

// continue while we are OUTSIDE the tol.


Slide18 l.jpg

The Mudd Meander…

public static void main(String[] args)

{

H.pl(“How many steps?”);

int W = H.ni(); // get width (W) from the user

int p = 0; // the student’s initial position is 0

while ( Math.abs(p) < W )

{

p = p + (int)(3*Math.random())-1; // update position

printPosition(p,W); // print one line

}

}

public static void printPosition(int p, int W)

{

}