代写代考 CS 1027 Computer Science Fundamentals II

Assignment 2
Learning Outcomes
In this assignment, you will get practice with:
CS 1027 Computer Science Fundamentals II

Copyright By PowCoder代写 加微信 powcoder

• Creating a subclass
• Overriding methods
• Using instanceof to determine the class of an Object
• Using Generics
• Working with linked data structures
• Using loops and conditionals
Introduction
Wordle is a popular game that was only released in October of last year and now has millions of people’s attention. This word game can be described as a mix of hangman and Mastermind. The rules are relatively simple. You have 6 guesses to find a 5-letter word. With each guess, you get information about how the letters of your guess relate to a mystery word. Each letter in your guess is labeled with respect to a mystery word as a correct letter, a used letter, or an unused letter. For instance, if the mystery word was “WHILE” but your guess was “SHEET”, then the labelling would be as follows: S unused, H correct, E used, E used, and T unused. That information can inform the next guess. Each subsequent guess helps narrow down what the mystery word could be.
This novel game may be a starting point for a whole family of games. We are going to create some tools to help explore some possible variants of Wordle. Although much thought was put into these game rules, our tools will to be less constrained to broaden the possibilities. For example, both length of word and number of guesses will be arbitrary. Along with lifting these numerical constraints, we are going to lift textual constraints in our tools to allow different letters other than A-Z. In particular, the tools will be able to deal with characters other than A-Z allowing for more variants for a Wordle-esque game. We retain the idea of labelling a words’ letters according to a mystery word.
Our main class, WordLL, will be a non-graphical text-based utility. Simple interfaces for WordLL are provided in WordLLExamples. Below is an example run of WordLLExamples in action where bold words are guesses entered by keyboard and lines starting with “Word:” show a history of results. Note that letters are decorated/surrounded with either “-“, ”+”, or “!” which correspond to unused, used, and correct. In the original Wordle game, colours indicate this information: unused letters are grey(-), used are yellow(+), and correct are green(!).
enter a word (XX to stop):SHORE
enter a word (XX to stop):BEAR
Word: -B- +E+ -A- +R+
enter a word (XX to stop):REJECT
Word: +R+ +E+ -J- !E! -C- -T-
Word: -B- +E+ -A- +R+

Assignment 2
CS 1027 Computer Science Fundamentals II
Word: -S- -H- +O+ +R+ +E+
Word: +R+ +E+ -J- !E! -C- -T-
Word: -B- +E+ -A- +R+
enter a word (XX to stop):ORDER
You got it!
Word: !O! !R! !D! !E! !R!
Word: -S- -H- +O+ +R+ +E+
Word: +R+ +E+ -J- !E! -C- -T-
Word: -B- +E+ -A- +R+
enter a word (XX to stop):XX Provided files
The following is a list of files provided to you for this assignment. Do no not alter LinearNode.java. The other two files are provided to help you understand the requirements of the assignment and are not to be submitted.
• LinearNode.java (from the notes)
• TestWordLL.java (some tests to check your code which may differ from Gradescope’s
• WordLLExamples.java (a collection of uses for your finished code)
• words (a text file with many words)
Classes to Implement
For this assignment, you must implement four Java classes: Letter, Word, WordLL, and ExtendedLetter. Follow the guidelines for each class below.
In all these classes, you can implement more private (helper) methods, if you want to, but you may not implement more public methods. You may not add instance variables other than the ones specified below nor change the variable types or accessibility (i.e. making a variable public when it should be private). Penalties will be applied if you implement additional instance variables or change the variable types or modifiers from what is described here.
Letter.java
This class represents a single letter that will be used in the game. Each game letter also has an accompanying integer label which indicates whether it is used, unused, or correct with respect to the mystery word.
The class must have the following private variables, and constants:
• letter (char)
• label (int)
• UNSET, UNUSED, USED, CORRECT (int) (constants that have unique values; these are the
possible values for the “label” instance variable)

Assignment 2
CS 1027 Computer Science Fundamentals II
The class must have the following public methods:
• public Letter(char c) [constructor]
• Initialize label to UNSET and set the value of instance variable letter to c
• public boolean equals(Object otherObject)
• First checks whether otherObject is of the class Letter, and if not the value false
is returned. If otherObject is of the class Letter, then the “letter” attributes of otherObject and this object are compared: If they are the same the value true is returned, otherwise false is returned.
• public String decorator()
• Returns “+” (if the “label” attribute is USED), “-“ (if the “label” attribute is
UNUSED), “!(if the “label” attribute is CORRECT), or “ “ (if the “label” attribute is
UNSET; note this is a space). • public String toSt”ring()
• an overridden method that gives a representation of letter & label which uses the helper method decorator. The String returned is of the form “dCd”, where C is the “letter” attribute of this object and d is the String returned by the decorator() method.
• from the Introduction, we can see some examples of Letter.toString():
▪ E in the fourth location is CORRECT
”, “-J-”, “!E!”, “-C-”, “-T-”
are letters that are USED (at least the E in the second location)
are letters that are UNUSED
• public void setUnused()
• used to change the value of attribute “label” to UNUSED
• public void setUsed()
• used to change the value of attribute “label” to USED
• public void setCorrect()
• used to change the value of attribute “label” to CORRECT
• public boolean isUnused()
• returns true if the attribute “label” is set to UNUSED
• otherwise returns false
• public static Letter[] fromString(String s)
• Produces an array of objects of the class Letter from the string s given as
parameter. For each character in s a Letter object is created and stored in the array. The Letter objects are stored in the array in the same order in which the corresponding characters appear in s.
This class represents a word in the game that is comprised of any number of letters. Each letter is represented by a Letter object. The Letter objects are stored in a linked list formed by objects of the class LinearNode. Each node in the linked list stores an object of the class Letter. The most important instance method of this class is labelWord which labels Letter objects with respect to a mystery word. This is the trickiest method of this assignment.

Assignment 2
CS 1027 Computer Science Fundamentals II
The class must have the following private variables:
• firstLetter (LinearNode): A reference to the first node in the linked list
representing the word corresponding to this object. The class must have the following public methods:
• public Word(Letter[ ] letters) [constructor]
• Initialize the Word object so the Letter objects in array “letters” is stored within its
linked structure. Instance variable firstLetter must point to the first node of the linked list.
For example, the invocation to the constructor passing as parameter an array of Letter objects corresponding to guess “BEAR” in page 1 would create the following linked list:
firstLetter
Object of class LinearNode
• public String toString()
• Creates a String of the form: “Word: L1 L2 L3 … Lk”, where each Li is the string
produced by invoking the toSting method on each Letter object of this Word.
• from the Introduction, we can see examples of the output of this toString()
method: ▪“” ▪“”
• public boolean labelWord(Word mystery)
• takes a mystery word as a parameter and updates each of Letters’ “label”
attribute contained in this Word object with respect to the mystery word
• returns true if this word is identical in content to the mystery word
• To understand how the “label” attribute of the Letter objects stored in the linked
list of a Word object are updated, consider an example. Suppose that the mystery word is “ORDER” and that this object stores Letter objects corresponding to the word “BEAR”, then the “label” attributes of the Letter objects would be updated as follows:
▪ label for Letter object corresponding to ‘B’ is UNUSED ▪ label for Letter object corresponding to ‘E’ is USED
▪ label for Letter object corresponding to ‘A’ is UNUSED ▪ label for Letter object corresponding to ‘R’ is USED
Object of class Letter
Word: +R+ +E+ -J- !E! -C- -T-
Word: -B- +E+ -A- +R+

Assignment 2
WordLL.java
CS 1027 Computer Science Fundamentals II
This class is a central repository for information about a WordLL game: It stores a mystery word and all word guesses tried so far. It keeps a history of the past word guesses in a linked structure. Its name is a bit of play on words—Word-Linked-List.
The class must have the following private variables:
• mysteryWord (Word)
• history (LinearNode)
mysteryWord history
Object of class LinearNode
Object of class Word
Object of class LinearNode
The class must have the following public methods:
• public WordLL(Word mystery) [constructor]
• Initialize an empty history
• set the mysteryWord attribute to the parameter mystery
• public boolean tryWord(Word guess)
Object of class Letter
• takes a Word as an argument to test against this games’ mystery word
• updates the label of all the letters contained within Word guess (using labelWord) and adds Word guess to the front the of history (you must create a node of the class LinearNode, store the Word guess object in it and then link this node to the
front of the linked list pointed by history)
• returns true if the word represented by guess is identical to the word represented
by mysteryWord, otherwise returns false
• public String toString()
• Creates a String representation of the past guesses with the most recent guess first. From the Introduction, we can see examples of the strings produced by this method toString() after every guess. For instance after the third guess in the example of page 1 this is what results of invoking method toString():
“Word: -S- -H- +O+ +R+ +E+
Word: +R+ +E+ -J- !E! -C- -T-
Word: -B- +E+ -A- +R+
“\n” after each word.
Note the end of line

Assignment 2
ExtendedLetter.java
CS 1027 Computer Science Fundamentals II
This class is a subclass of Letter and extends the functionality. Instead of relying on a single char to represent the content of a Letter object, objects of this class will use a String instance variable and will further introduce the concept of being related to other ExtendedLetter objects. This class adds more features to broaden the notion of a letter that will be used in the game.
The class must have the following private variables, and constants:
• content (String)
• family (int)
• related (boolean)
• SINGLETON (int) constant equal to -1
The class must have the following public methods:
• public ExtendedLetter(String s) [constructor]
• Initialize instance variables of the superclass
▪ super(c) where c is an arbitrary char (it doesn’t matter which since it will not be used)
• Initialize the instance variables as follows:
▪ content is set to the String parameter s ▪ related is set to false
▪ family is set to SINGLETON
• public ExtendedLetter(String s, int fam) [constructor]
• Initialize instance variables of the superclass
▪ super(c) where c is an arbitrary char (it doesn’t matter which since it will not be used)
• Initialize the instance variables as follows:
▪ content is set to the String parameter s
▪ related is set to false
▪ family is set to the int parameter fam; this is a positive number which
indicates that any ExtendedLetter object with the same value in instance
variable family will be consider related to this ExtendedLetter object
• public boolean equals(Object other)
• return false if the parameter other is not an instanceOf ExtendedLetter • otherwise
▪ it will set the instance variable related of this object to true if the family instance variable of other is the same as this.family.
▪ return true if the instance variable content of other is equal to the instance variable content of this object;
▪ otherwise it returns false

Assignment 2
CS 1027 Computer Science Fundamentals II
• public String toString()
• an overridden method that gives a String representation of this ExtendedLetter
• If this ExtendedLetter object is unused (its label instance variable has value
UNUSED) and its instance variable related has value true, return the string “.C.” where C is equal to this.content. For example, if this.content is and this.related is true, this method would return
• Otherwise, this method should return a string “+C+”, “!C!”,“-C-”, or “ C ” depending of the value returned by method decorator() from the superclass, where C is equal to this.content.
• public static Letter[] fromStrings(String[] content,int[] codes)
• Creates an array letters of Letter objects of the same size as the size of the array
content received as parameter. This array letters will be returned by the method
after storing in it the following information:
• If parameter codes is null then the i-th entry of array letters will store an
ExtendedLetter object created with the constructor ExtendedLetter(content[i]).
• If codes is not null, then the i-th entry of array letters will store an ExtendedLetter
object created with the constructor ExtendedLetter(content[i],codes[i]). To Run the Program
If you are running the program from the terminal, place all files in the same directory, compile them with javac and run the program by typing java WordLLExamples.
If you are using Eclipse, put the file called words in the root folder of your project (not inside the src folder) and run the WordLLExamples class.
There are two modalities of the program. If in the main method of WordLLExamples you invoke method playEnglish, the program will play Wordle with words; if you invoke method playCards you will have to guess four Euchre cards.
Marking Notes Functional Specifications
• Does the program behave according to specifications?
• Does it produce the correct output and pass all tests?
• Are the classes implemented properly?
• Does the code run properly on Gradescope (even if it runs on Eclipse, it is up to you to
ensure it works on Gradescope to get the test marks)
• Does the program produces compilation or run-time errors on Gradescope?
• Does the program fail to follow the instructions, (i.e. changing variable types, etc.)

Assignment 2
Non-Functional Specifications
CS 1027 Computer Science Fundamentals II
• Are there comments throughout the code (Javadocs or other comments)?
• Are the variables and methods given appropriate, meaningful names?
• Is the code clean and readable with proper indenting and white-space?
• Is the code consistent regarding formatting and naming conventions?
• Submission errors (i.e. missing files, too many files, etc.) will receive a penalty of 5%
• Including a “package” line at the top of a file will receive a penalty of 5%
Remember you must do all the work on your own. Do not copy or even look at the work of another student. All submitted code will be run through similarity-detection software.
Submission (due Monday, February 28, 2022 at 11:55pm ET)
Assignments must be submitted to Gradescope, not on OWL. If you are new to this platform,
see these instructions on submitting on Gradescope. Rules
• Please only submit the files specified below.
• Do not attach other files even if they were part of the assignment.
• Do not upload the .class files! Penalties will be applied for this.
• Submit the assignment on time. Late submissions will receive a penalty of 10% per day.
• Forgetting to submit is not a valid excuse for submitting late.
• Submissions must be done through Gradescope.
• You are expected to perform additional testing (create your own test harness class to do this) to ensure that your code works for other dice combinations as well. We are providing you with some tests but we may use additional tests that you haven’t seen before for marking.
• Assignment files are NOT to be emailed to the instructor(s) or TA(s). They will not be marked if sent by email.
• You may re-submit code if your previous submission was not complete or correct, however, re-submissions after the regular assignment deadline will receive a penalty.
Files to submit
• Letter.java
• Word.java
• WordLL.java
on Gradescope, you will NOT get the marks! Make sure it works on Gradescope to
If your code runs on Eclipse but not
get these marks.

Assignment 2
• ExtendedLetter.java Grading Criteria
Total Marks: [20]
Functional Specifications:
[1] Letter.java
[2] Word.java
[2] WordLL.java
[1] ExtendedLetter.java [12] Passing Tests
Non-Functional Specifications:
CS 1027 Computer Science Fundamentals II
[0.5] Meaningful variable names, private instance variables [0.5] Code readability and indentation
[1] Code comments

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com