Question
Write a class City. The constructor takes a String parameter. This is provided for you. You need to copy the starter code from Codecheck You
Write a class City. The constructor takes a String parameter. This is provided for you. You need to copy the starter code from Codecheck
You provide the methods:
public String getCity() gets the name of the city
public boolean doubleLetter() determines if the city name contains a double letter. Returns true is it does. Otherwise it returns false. Note: double letter means two of the same letter next to each other. The test is case-insensitive. For example Seacliff and Lloydton have a double letters. Saratoga does not.
Hints
The loop needs to stop on the next to the last letter (to avoid StringIndexOutOfBoundsException)
Do not change the instance variable.
Use the following file:
CityTester.java
/** * Test the City class */ public class CityTester { public static void main(String[] args) { City name = new City("Saratoga"); System.out.println("Double letter?: " + name.doubleLetter()); System.out.println("Expected: false"); name = new City("Seacliff"); System.out.println("Double letter?: " + name.doubleLetter()); System.out.println("Expected: true"); name = new City("Lloydton"); System.out.println("Double letter?: " + name.doubleLetter()); System.out.println("Expected: true"); System.out.println(name.getCity()); System.out.println("Expected: Lloydton"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started