Skip to main content

Homework 3: Methods, Conditionals, & Strings

Due: 2024-09-31 23:59:00EDT

In this assignment you will be working with methods, conditionals, and Strings.

Requirements:

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.

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.

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.

Although we covered recursion, you are not allowed to use recursion on this assignment. Don’t worry, you will get lots of opportunities this semester to use recursion!

1. Playing with Words!

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 the labs.

1.1 abecedarian

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.

1.2 doubloon

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 returns a boolean indicating 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. Additionally, to make this easier to implement, you should only consider the English letters a-j. If the word contains a letter that isnt between a and j (inclusive), your method can return false.

Note: 10/02 9:00am - If the word contains a letter that isnt between a and j (inclusive) OR THAT ISN’T BETWEN A AND J, your method can return false.

1.3 Isopsephy

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.

1.3.1 avgIsopsephy

Write a method called avgIsopsephy that takes in 3 words (strings) and returns a double indicating the average isopsephy value of the words. If any of the words do not contain 4 letters, the method should return -1.

Sample inputs / outputs:
avgIsopsephy("abcd", "efgh", "ijlk") => 26.0
avgIsopsephy("some", "test", "word") => 58.666

1.3.2 isopsephySumEqual

Write a method called isopsephySumEqual that takes in 2 words (strings) 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.

1.4 Reverse String

Write a method called reverseString that takes in a string and returns the reverse string. If the word does not contain 5 letters, return an empty string.

Hint: String concatenation might be helpful here.

README.txt

In a text file called README.txt answer the following questions:

  1. How much time did you spend on the homework
  2. What did you learn from this homework
  3. optional: What did you struggle with during this homework
  4. optional: any other feedback you would like to share

Dont forget: make sure to fill in the header in all of your java files.

Submitting

Submit the following files to the assignment called HW03 on Gradescope:

  1. WordsWordsWords.java
  2. 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.