Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago