files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine...

17

Transcript of files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine...

Page 1: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,
Page 2: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

Background

Do you like playing word games such as Scrabble (https://en.wikipedia.org/wiki/Scrabble) and others? If you answered ‘yes’, then this is will be a fun assignment for you!

In the Word Games assignment, you are asked to implement some word games in an interactive and menu-driven program written in Java. In addition, you are expected to demonstrate skills and best practices regarding documentation, testing, error handling, code commenting, and code indentation.

The core three problems of this assignment are the Substring Problem, the Points Problem, and the Palindrome Problem. There is also an interactive main menu, and a dictionary of words to test the solution against.

The following headings describe the various assignment functionality, tasks, marking rubric, and submission instructions.

Substring problem

Have you ever played a word game, and you have a fragment of a word in mind, but you are not sure what words use it? Then this is the problem for you!

For this problem, the term substring in programming can also mean the fragment. Consider the following examples of English-language substrings based on prefixes, infixes, or suffixes:

• Prefix: The substring “fore” is a prefix of forehead and foreword.• Infix: The substring “s” is an infix of the plural of passerby as passersby. Other examples

are slang words such as “bloody” in fanbloodytastic and “blooming” in absobloominglutely.• Suffix: The substring “ful” is a suffix of helpful and cheerful.

To solve the substring problem, you need to determine whether a substring is a prefix and/or infix and/or suffix of a given word. Take care when more than one of these applies at the same time, such as “na” as an infix and suffix of “banana”.

Points problem

Have you ever played a word game, and you want to earn as many points as possible? Then this is the problem for you!

For this problem, the points will be based on the Scrabble word game ( https://en.wikipedia.org/wiki/Scrabble ) in the English language. The points for each letter are summarised in the table below:

Points Letters1 a, e, i, l, n, o, r, s, t, u2 d, g3 b, c, m, p4 f, h, v, w, y5 k8 j, x10 q, z

To solve the points problem, you need to calculate the number of points for a given word.

Page 3: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

Palindrome problem

Have you ever played a word game, and you sometimes have duplicates of the same letters? Then this is the problem for you!

When you have duplicate letters, you can sometimes use them twice for words that can be spelled the same both forwards and backwards. This is known as a palindrome. For example, if you have “nnoo”, you can spell “noon”, and if you have “ddeerr”, you can spell “redder”. This works for words with an odd number of letters too, but the one in the middle will not be repeated, such as “radar”, and “racecar”.

To solve the palindrome problem, you will need to determine if a given word is a palindrome or not.

Dictionary

For all these word problems, you will need some sample words to test the correctness of your solutions. These will be stored in a file called “dictionary.txt” in the top level of your project solution. Importantly, each of the solutions to the three main problems needs to read and process all words in the dictionary.

Consider the following list of words that you can use as your dictionary.

passersbyabsobloominglutelynanabananathequickbrownfoxjumpsoverthelazydogammwownoonradarredderracecarredivideraibohphobiatattarrattat

Note that any dictionary may be used to test your work, however, you may make the following assumptions:

1. There is exactly one word per line.2. All words are in lowercase.3. All characters are ‘a’ to ‘z’ only.4. There are no blank lines.

Page 4: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

Menu selection

A separate method called getSelection() will be implemented to print the available menu options, receive the user’s selection with Java’s Scanner class, and return the answer to the calling method. There are four menu options altogether – one for each problem, and one to exit the program. Refer to “Sample Program Output” below for an example of the menu.

Program organisation

The whole solution will be placed in a single class called WordGames. This includes the main() method that will be responsible for processing menu selections and initiating the corresponding problem that matches the selection. This will be repeated until the exit option is selected.

The WordGames class has a method for each of the five main components of the assignment: main(), getSelection(), substringProblem(), pointsProblem(), and palindromeProblem(). These are all static methods as per a functional style of programming. Refer to Lecture 4.1 “Class definitions” (slides 21-25) and Live Discussion 1 for more information on this.

The WordGames class also has a constant class variable called DICTIONARY for the name of the dictionary file (dictionary.txt). This prevents repetition when referring to the dictionary from multiple locations. Since the five methods use the static modifier, the constant DICTIONARY class variable will also need to use the static modifier.

Program output

The following session trace shows the program output after processing each option once with the provided dictionary, then trying an invalid option, then exiting. Your solution needs to match this output.

Note that there is a blank line after each menu selection and the completion of each problem for readability.

Welcome to the Word Games program menu.Select from one of the following options.1. Substring problem.2. Points problem.3. Palindrome problem.4. Exit.Enter your selection: 1

Substring problem.Enter a substring: tpassersby - not foundabsobloominglutely - infixnana - not foundbanana - not foundthe - prefixquick - not foundbrown - not foundfox - not foundjumps - not foundover - not foundthe - prefixlazy - not found

Page 5: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

dog - not founda - not foundmm - not found wow - not found noon - not found radar - not found redder - not found racecar - not found redivider - not found aibohphobia - not foundtattarrattat - prefix - infix - suffix

Welcome to the Word Games program menu.Select from one of the following options.1. Substring problem.2. Points problem.3. Palindrome problem.4. Exit.Enter your selection: 2

Points problem.passersby is worth 16 points.absobloominglutely is worth 28 points.nana is worth 4 points.banana is worth 8 points.the is worth 6 points.quick is worth 20 points.brown is worth 10 points.fox is worth 13 points.jumps is worth 16 points.over is worth 7 points.the is worth 6 points.lazy is worth 16 points.dog is worth 5 points.a is worth 1 point.mm is worth 6 points. wow is worth 9 points. noon is worth 4 points. radar is worth 6 points. redder is worth 8 points. racecar is worth 11 points. redivider is worth 14 points. aibohphobia is worth 23 points. tattarrattat is worth 12 points.

Welcome to the Word Games program menu.Select from one of the following options.1. Substring problem.2. Points problem.3. Palindrome problem.4. Exit.Enter your selection: 3

Palindrome problem. passersby is not a palindrome absobloominglutely is not a palindrome

Page 6: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

nana is not a palindromebanana is not a palindromethe is not a palindromequick is not a palindromebrown is not a palindromefox is not a palindromejumps is not a palindromeover is not a palindromethe is not a palindromelazy is not a palindromedog is not a palindromea is a palindromemm is a palindrome wow is a palindrome noon is a palindrome radar is a palindrome redder is a palindrome racecar is a palindrome redivider is a palindrome aibohphobia is a palindrome tattarrattat is a palindrome

Welcome to the Word Games program menu.Select from one of the following options.1. Substring problem.2. Points problem.3. Palindrome problem.4. Exit.Enter your selection: 5

Invalid option. Try again.

Welcome to the Word Games program menu.Select from one of the following options.1. Substring problem.2. Points problem.3. Palindrome problem.4. Exit.Enter your selection: 4

Goodbye!

Task 1: Data dictionary

Create a data dictionary for the contents of the pointsProblem() method. Use the appropriate template from the “Documentation and testing templates” resource on the LMS.

Note: Tasks 1-4 follow the steps of the Program Design Routine (PDR) for the pointsProblem() method only. Although you are not being assessed on the PDR for all problems of the assignment, it remains a good approach to problem solving.

Task 2: Pseudocode

Page 7: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

Write a complete pseudocode for the contents of the pointsProblem() method. Don’t forget to add line numbers.

Task 3: Test data table

Create a test data table for the pointsProblem() method using the following data sets. Use the appropriate template from the “Documentation and testing templates” resource on the LMS.

Data set WordsFirst dictionary aSecond dictionary jumpsThird dictionary lazy

dogFourth dictionary quick

brownfox

Task 4: Desk check table

Create a desk check table for the contents of the pointsProblem() method using the “third dictionary” dataset from Task 3. The line numbers must match your answer to Task 2. Use the appropriate template from the “Documentation and testing templates” resource on the LMS. Consider using a landscape page orientation if you need more space.

Task 5: Implementation

Implement the WordGames program as a NetBeans 8.2 project using Java 8.

Your solution must also include the following general features:1. Error handling for user input and opening files.2. Consistent code indentation with one level of indentation per block.3. Code commenting for the class, all five methods, and some inline comments.

Submitting your assignment

When you have completed your answers, submit the assessment on the LMS system. You should submit the following:

• Submit your answers in a document called xxx_cse1ofx_assessment1.docx for your answers for Tasks 1, 2, 3, and 4.

• Submit your answers in a Zip archive called xxx_cse1ofx_assessment1.zip for your answers for Task 5.

A copy of the dictionary file must reside in the Zip archive allowing the assessor to run your decompressed program immediately without moving files around or renaming file names/paths. I.e.: The dictionary must be referenced by a relative rather than absolute location.

Page 8: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

Assessment marking criteria

The complete marking rubric is given below.

Task 1: Data dictionary (5 points)

Page 9: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

• Data dictionary is incorrect. (0 points)• Data dictionary is seldom correct. (1 point)• Data dictionary is partly correct. (2 points)• Data dictionary is mostly correct. (3 points)• Data dictionary is correct. (4 points)• Data dictionary presentation is basic. (0 point)• Data dictionary presentation is professional. (1 point)

Task 2: Pseudocode (5 points)• Pseudocode is incorrect. (0 points)• Pseudocode is seldom correct. (1 point)• Pseudocode is partly correct. (2 points)• Pseudocode is mostly correct. (3 points)• Pseudocode is correct. (4 points)• Pseudocode presentation is basic. (0 point)• Pseudocode presentation is professional. (1 point)

Task 3: Test data table (5 points)• Test data table is incorrect. (0 points)• Test data table is seldom correct. (1 point)• Test data table is partly correct. (2 points)• Test data table is mostly correct. (3 points)• Test data table is correct. (4 points)• Test data table presentation is basic. (0 point)• Test data table presentation is professional. (1 point)

Task 4: Desk check table (5 points)• Desk check table is incorrect. (0 points)• Desk check table is seldom correct. (1 point)• Desk check table is partly correct. (2 points)• Desk check table is mostly correct. (3 points)• Desk check table is correct. (4 points)• Desk check table presentation is basic. (0 point)• Desk check table presentation is professional. (1 point)

Task 5a: Program design (4 points)• Class name is incorrect. (0 points)• Class name is correct. (1 point)• Dictionary class variable is incorrect. (0 points)• Dictionary class variable is correct. (1 point)• Method signatures are incorrect. (0 points)• Method signatures are partly correct. (1 point)• Method signatures are correct. (2 points)

Task 5b: Error handling (4 points)• Solution for accepting menu options is prone to runtime errors. (0 points)• Solution for accepting menu options is somewhat prone to runtime errors. (1 point)• Solution for accepting menu options is robust regarding runtime errors. (2 points)• Solution for opening the dictionary file is prone to runtime errors. (0 points)

Page 10: files.transtutors.com€¦  · Web viewTo solve the palindrome problem, you will need to determine if a given word is a palindrome or not. Dictionary. For all these word problems,

• Solution for opening the dictionary file is somewhat prone to runtime errors. (1 point)• Solution for opening the dictionary file is robust regarding runtime errors. (2 points)

Task 5c: main() method (2 points)• Implementation is incorrect. (0 points)• Implementation is partly correct. (1 point)• Implementation is correct. (2 points)

Task 5d: getSelection() method (2 points)• Implementation is incorrect. (0 points)• Implementation is partly correct. (1 point)• Implementation is correct. (2 points)

Task 5e: substringProblem() method (4 points)• Implementation is incorrect. (0 points)• Implementation is seldom correct. (1 point)• Implementation is partly correct. (2 point)• Implementation is mostly correct. (3 points)• Implementation is correct. (4 points)

Task 5f: pointsProblem() method (4 points)• Implementation is incorrect. (0 points)• Implementation is seldom correct. (1 point)• Implementation is partly correct. (2 point)• Implementation is mostly correct. (3 points)• Implementation is correct. (4 points)

Task 5g: palindromeProblem() method (4 points)• Implementation is incorrect. (0 points)• Implementation is seldom correct. (1 point)• Implementation is partly correct. (2 point)• Implementation is mostly correct. (3 points)• Implementation is correct. (4 points)

Task 5h: Coding conventions (6 points)• Code indentation is poor. (0 points)• Code indentation needs improvement. (1 point)• Code indentation is good and only needs minor improvement. (2 points)• Code indentation is excellent. (3 points)• Code commenting is poor. (0 points)• Code commenting needs improvement. (1 point)• Code commenting is good and only needs minor improvement. (2 points)• Code commenting is excellent. (3 points)

Total: 50 points