Assignment 1
Arrays, Strings and Static Methods
Submit before 11:30 PM Saturday January 17

Overview

You will work with arrays, strings and APIs to create programs that score a word for the game Scrabble and report basic statistics of two stories.

You may collaborate with one or two other people in the class. If you do that, it's very important that you work together on all elements of the assignment. Common, effective activities should include discussing the approach together, making suggestions as one person types, explaining code to each other and critiquing written code. Your primary goals of the assignments should be to learn course concepts and improve your skills as a programmer. It is up to you to engage in practices that will achieve these goals.

Requirements

Because I will (probably) run your code automatically, it's important to follow the instructions on naming your package, files and methods. For this assignment, your files should be in a package named assn1. To receive credit, your code must compile and run. However, your code doesn't necessarily need to implement all cases in order to receive partial credit.

Scrabble scoring

Write a static method called scoreWord that takes a string as input. This method should take a string of upper-case letters including the blank ("_") character. If the given string is a valid word (present in the online dictionary), it should return its scrabble score (see tile scores for Scrabble in English). If the string is not a valid word, it should return 0. Note that the blank character can represent any letter. You may assume that the string will have at most one blank character.

For example, the method call scoreWord("QUICK") should return a score of 20 (Q=10, U=1, I=1, C=3, K=5), but scoreWord("ZXRT") should return a score of 0 since it's not a valid word.

Write another static method, also called scoreWord, that takes two strings as input. The first string indicates the proposed word for scoring (as before). The second string indicates the squares for placing the word. These squares may have multipliers for a letter or the whole word. The string representing the squares uses the following codes:

CharacterMeaning
_regular square --- no bonus
ddouble letter score
ttriple letter score
Ddouble word score
Ttriple word score

For example, the method call scoreWord("QUICK", "d____T") should return a score of 90 (Q=10*2, U=1, I=1, C=3, K=5; and then tripling the sum).

For writing your methods, put them in a class called Score (file name will be Score.java). Make sure that your methods are public.

You may assume that the dictionary file (wordsEn.txt, available online) is in the data folder.

Story Analysis

Using the BagOWords class, write a program that analyzes these two short stores: The Cask of Amontillado and The Open Window. The program should produce a report with the following information:

  • The total number of words in the text
  • The number of different words
  • The ratio of the number of different words to the total number of words
  • The list of words (in any order) that occur more than 2% of the time and the percentage that they occur.

The main method of your program should write the report to standard output. You may assume that these two files are in the data folder.

You shouldn't need to modify the BagOWords class. Just import the file into your assn1 package. Call your file Story.java and give it the corresponding class name.

Submission

Zip up your assn1 package and submit it as assn1.zip on D2L. If you work with one or two other people, only one person needs to submit. In the submissions comments, indicate who you worked with.