In this assignment you will be working with methods, Strings
, and Arrays
.
Requirements:
- Every method you created should be tested in the class’s main method.
- Every java file should have a header. However, DO NOT PUT YOUR NAME IN YOUR HEADERS. On gradescope we grade your assignments anonymously so including your name in your Java file will defeat that purpose. However, please include your name in your README.txt
- Every method should contain a javdoc that briefly describes the method, lists the params, and the return type/value. Use the notation that we used in lectures.
- Dont forget to add
public static
to every method signature. If a method does not have these, the autograder will fail and you wont receive any points for that method.
For these methods, you are not allowed to use a loop since we did not cover loops yet. WARNING:Using a loop in a method will result in getting 0 points for that method!
Note, in the examples,
*
indicates user input.
Update 02/11: WARNING: In this assignment you are NOT ALLOWED to import any packages. For example, you cannot use the builtin
Arrays
java class to reverse an array. Doing so will result in earning ZERO POINTS for a method that uses it.
Update 02/12: IF YOUR CODE DOES NOT COMPILE ON GRADESCOPE, YOU WILL NOT RECEIVE ANY POINTS FROM THE AUTOGRADER. When you submit, make sure to check if the autograder compiles and if you test some of the public test cases.
Write a program called WordsWordsWords.java
that implements the following methods. Make sure to test the methods in the file’s main method.
Hint: You will want to use some of the
String
methods covered in Lab02 and Lab03.
A word is said to be “abecedarian” if the letters in the word appear in alphabetical order. For example, the following are all six-letter English abecedarian words:
abdest, acknow, acorsy, adempt, adipsy, agnosy, befist, behint, beknow, bijoux, biopsy, cestuy, chintz, deflux, dehors, dehort, deinos, diluvy, dimpsy
Write a method called isAbecedarian
that takes a String and returns a
boolean indicating whether the word is abecedarian.
Your method should only work for words that have 6 letters. If a word does not have 6 letters, the method should return false
.
The method should work for non-alpha numeric characters. For example, the method should return true if the string is 456789
.
A word is said to be a “doubloon” if every letter that appears in the word appears exactly twice. Here are some example doubloons found in the dictionary:
Abba, Anna, appall, appearer, appeases, arraigning, beriberi, bilabial, boob, Caucasus, coco, Dada, deed, Emmett, Hannah, horseshoer, intestines, Isis, mama, Mimi, murmur, noon, Otto, papa, peep, reappear, redder, sees, Shanghaiings, Toto
Write a method called isDoubloon
that takes a string and checks whether it is
a doubloon. To ignore case, invoke the toLowerCase method before checking.
Your method should only work for words that have 6 letters. If a word does not have 6 letters, the method should return false
. If the words contains a character that is not an English letter, i.e. a character that is not a-z
or A-Z
, the method should return false
.
Hint: it might be helpful to create an array to keep track of how many times each character appears.
Isopsephy is the practice of adding up the number values of the letters in a word to form a single number, in Hebrew we often refer to this as Gematria.
Hint: you might find it helpful to create a method that returns the isopsephy value of a word. When often refer to these types of methods as helper methods since they implement some functionality that you use over and over again.
Write a method called avgIsopsephy
that takes in 5 words and returns the average isopsephy value of the words. If any of the words do not contain 4 letters, the method should return -1.
Write a method called isopsephySumEqual
that takes in 2 words and determines if the sums of the isopsephy of each word are equal to each other. The method should return a boolean. Again, if any of the words do not contain 4 letters, the method should return false
.
Write a method called reverseString
that takes in a string and returns the reverse string. If the word does not contain 10 letters, return an empty string.
Hint: String concatenation might be helpful here.
In a file called ArrayMethods.java
, write the following methods.
Write a method called isAbecedarian
that takes an array of characters and returns a
boolean indicating whether the characters appear in alphabetical order.
Your method should only work for arrays that have 6 characters. If a word does not have 6 characters, the method should return false
.
Write a method called isAbecedarian
that takes an array of integers and returns a
boolean indicating whether the integers are sorted in ascending order. Note: 1234 is an example of ascending order while 4321 is descending order.
Your method should only work for arrays that have 6 integers. If a word does not have 6 integers, the method should return false
.
Write a method called isAbecedarian
that takes an array of double and returns a
boolean indicating whether the doubles are sorted in descending order. Note: 1234 is an example of ascending order while 4321 is descending order.
Your method should only work for arrays that have 6 doubles. If a word does not have 6 doubles, the method should return false
.
Write a method called isDoubloon
that takes an array of characters and checks whether each character in the array appears twice.
Your method should only work for arrays that have 6 letters. If a array does not have 6 characters, the method should return false
. Your method should also work for only lower case letter (a-z). If the array contains a character that is not a lower case letter, the method should return false
.
Write a method called avgIsopsephy
that takes in an array of 5 words and returns the average isopsephy value of the words. If any of the words do not contain 4 letters, the method should return -1.
Write a method called maxIsopsephy
that takes in an array of 5 words and returns the word that has the largest isopsephy value. If any of the words do not contain 4 letters, the method should return an empty String (""
).
Write a method called minIsopsephy
that takes in an array of 5 words and returns the word that has the smallest isopsephy value. If any of the words do not contain 4 letters, the method should return an empty String (""
).
Write a method called isopsephySumEqual
that takes in an array of 2 words and determines if the sums of the isopsephy of each word are equal to each other. The method should return a boolean. Again, if any of the words do not contain 4 letters, the method should return false
.
Write a method called reverse
that takes in an array of integers and returns an array where the order of the integers is reversed. If the word does not contain 10 integers, return an empty array.
Write a method called reverse
that takes in an array of characters and returns an array where the order of the characters is reversed. If the array does not contain 10 characters, return an empty array.
Write a method called reverse
that takes in an array of Strings and returns an array where the order of the strings is reversed. If the array does not contain 10 strings and if each string does not contain 5 characters, return an empty array.
In a text file called README.txt
answer the following questions:
Dont forget: make sure to fill in the header in all of your java files.
Submit the following files to the assignment called HW03
on Gradescope:
ArrayMethods.java
WordsWordsWords.java
README.txt
Make sure to name these files exactly what we specify here and name the methods exactly what we specify too. Otherwise, our autograders might not work and we might have to take points off.