Skip to content

HW due 3/20 #4

@asaini

Description

@asaini

1. Divisor Pattern Art

Print a table of size NxN where an entry (i, j) is:

  • @ @ character + 1 space character if i divides j or j divides i
  • Two empty space characters, otherwise

For example:

@ @ @ @ @ 
@ @   @   
@   @     
@ @   @   
@       @ 

2. Twenty Questions Game

Write a program which assumes a random integer X in some range, say 1 - 100,000. It prompts you to input a number and responds with the following information:

  • Input number is higher than X
  • Input number is lower than X
  • Input number is equal to X, in which case you win the game
    Your program gives 20 chances to guess the number and you lose if you fail to guess.

You can use Java's Math.random() to generate a random number. Note that it returns a double, but we want an int

3. Fibonacci

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Write a program which accepts as input an integer N and returns the N-th Fibonacci number. To test whether your program returned the correct number, go to Wolfram Alpha, and enter fibonacci(N) where N is your input integer

4. A Pretty Title

Write a program that calls a method printTitle that prints a phrase as a title by,

  1. converting it to title capitalization
  2. underlining each word, i.e. underlying all characters except spaces

For example,

printTitle("a tale of two cities", '*')

produces

A Tale of Two Cities
* **** ** *** ******

5. Who is more verbose : Dickens or Melville?

Fork the repo VerbosityCalculator and follow the instructions in the repo

6. Weekly requirements

7. Submission

Post a link to your homework GitHub repositories + link to your Medium post as comment to this issue by Friday 3/20 8pm.

Submission format: : Same as last week

Bonus Challenges! (optional)

Exercise: [optional] Write a method that counts the number of words in a string. For example,

coundWords("Eighty percent of success is showing up.")

returns 7.

Exercise: [optional] Write a method that computes the average word length. To compute the average, count the total number of letters in words (not including spaces) as well as the total number of words, and divide them. Make sure the result is a double, not an int. For example,

averageWordLength("Eighty percent of success is showing up.")

returns about 4.714.

Execise: [optional] Write a method that replaces all occurrences of "man" with "wo/man", "men" with "wo/men", "he" with "s/he", "his", with "his/her", and "him" with "him/her". Feel free to substitute your own preferred gender-neutral nouns and pronouns.

Exercise: [optional] Write a method that reverses a string by order of words (rather than characters). Treat punctuation as part of a word.

For example,

reverseWords("You miss 100% of the shots you don’t take.")

returns

"take. don't you shots the of 100% miss You"

For extra credit, try to preserve sentences by leaving punctuation at the end and fixing capitalization, so that the result is instead,

"Take don't you shots the of 100% miss you."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions