Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Java problem. Write a class City . The constructor takes a String parameter. This is provided for you. You need to copy the starter

A Java problem. 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:

1. public String getCity() gets the name of the city

2. 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

1) The loop needs to stop on the next to the last letter (to avoid StringIndexOutOfBoundsException)

2) Do not change the instance variable

---------------------------------------------------------------------------------------------------------------

City.java

public class City { private String city;

public City(String city) { this.city = city; } }

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago