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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!