Skip to main content.

Assignment 3: Static Methods

Objective: Practice writing static methods.

Due: Before the next class (Friday).

Set Up

In your terminal, go to the directory where you are keeping your repositories for CSCI209. Clone the repository for this assignment. Add your name to the README file.

Several of you have asked about how I ignore files in git. In the repository, look at the .gitignore file. This file contains a list of files that git should ignore, i.e., should not allow into the repository.

Writing Static Methods (50)

Write a class called StringUtils with static methods that manipulate strings. You're going to write this class from stratch. Make sure you add the file to your repository. Here are the specifications for the static methods:

/**
 * Reverses the given string.
 * @param string the String to reverse
 * @return the string backwards; e.g., "stars" --> "srats"
 */
public static String reverseString(String string)
/**
 * Tests if a string is a palindrome.  A palindrome is a word
 * that is the same forwards and backwards (ignoring spaces and casing).
 * Some palindromes: 
 * "kayak"
 * "A man A plan A canal Panama"
 *
 * You should consider upper and lower case letters as the same.
 * 
 * However, you don't need to consider punctuation as special cases,
 * i.e., "A man. A plan. A canal. Panama." will return false.
 *
 * @param s the String to test if it's a palindrome
 * @return true iff the String is a palindrome
 * @see http://www.palindromelist.com
 */
public static boolean isPalindrome(String string)

Use methods from the String or StringBuilder classes to help you write the methods.

In the README file, answer Why is it appropriate for these methods to be static?

After testing your methods individually, your main method should prompt the user for a potential palindrome (a String) and then display if that String is a palindrome. Below are some example runs of the program:

    This program determines if a word or phrase is a palindrome.
    
    What is the potential palindrome? ka Yak
    ka Yak is a palindrome. 
    This program determines if a word or phrase is a palindrome.
    
    What is the potential palindrome? kayak.
    kayak. is not a palindrome. 

Submitting Your Assignment

Submit your assignment by pushing the code and README.md to GitHub.

Reminders -- for the last time

Great! You got it working! Before you submit, review your code. Is your code written in an (relatively) understandable way? Any extra code that you no longer need? Do you have appropriate comments?

It is recommended that you [re?]clone your project in a new directory, and then make sure that you can compile and run your programs

Grading (50 pts)

You will be evaluated based on the correctness and style of your program: