Assignment 3: Static Methods
Objective: Practice writing static methods.
Due: Tuesday 11:59 p.m.
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.
Overview
The order in which I describe the assignment is not necessarily the way you should approach it. You will likely be jumping back and forth between files/classes.
Suggested Development Process:
- Implement the
reverse
method inStringUtilities
. Test it in themain
method with hard-coded values. - Call the
reverse
method in the Driver and display the results multiple times (without user input). - Implement the
main
method in theDriver
class to prompt the user for a String and then reverse it. - Follow a similar process for the
isPalindrome
method.
Implementing Static Methods (55)
StringUtilities
class
Write a class called StringUtilities
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.
StringUtilities
's main
method should test
the above methods with hardcoded values.
Note that the above methods should *not* print any output in the end. (It's fine if they display output while you're in the process of debugging.) Displaying output would be an unwanted side effect of calling your method; the documentation should say if it displays something.
Driver
class
After testing your methods individually, your Driver
class's 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.
Analysis (5)
In the README file, answer Why is it
appropriate for reverse
and isPalindrome
to
be static
?
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 (60 pts)
You will be evaluated based on the correctness and style of your program:
- (38 pts) StringUtilities' Static Methods
- (10 pts) reverseString
- (20 pts) isPalindrome
- (8 pts) main -- testing
- (10 pts) Driver's main
- (7 pts) code style
- (5 pts) explanation of why static