Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Based on the given references above and the class City in the last question, define a new Java class BCity for modeling Better Cities with

image text in transcribed

Based on the given references above and the class City in the last question, define a new Java class BCity for modeling "Better" Cities with the following requirements.

  1. This BCity class is a public subclass of the given class City
    1. This class has a specific instance field named bRList (type ArrayList of string) representing the list of better rules (of string type) governing the better city.
      1. This field is initialized with an empty ArrayList of string.
  2. It has one constructor with 3 parameters (String cN, int cP, String[] rules) :
    1. The first and second parameters are for the name and population of the city object, while the third parameter is for the rules.
    2. The body of this constructor first calls the corresponding constructor of its superclass with the two related input parameters.
    3. The constructor body then adds all elements of the input array parameter into its own specific field bRList.
  3. It has 2 public methods:
  • The method hasRu1e ( ) is for checking if the city includes a specific rule string.
    • The method accepts one input argument rule of string type and returns int value.
    • This method checks if the input argument rule appears in the field bRList and matches the string content of an element in the list bRLi st.
    • The method returns the index number of the first matched element found in the list.
  • The method returns -1 if no element found in the list matches the input argument rule o The method dispRList ( ) is for displaying information of the object on console.
    • The method has no input argument and no return value.
    • The method body first displays the general information of the city, then displays all its rules (one rule in a line) as sample program output below.

Sample Program Output

(Suppose City has: name "B City", Population 4, Rules: "Rule 11" and "Rule 12")

City: BCity, Pop: 4

Rule 11

Rule 12

O * Given reference, useful methods for accessing Java class ArrayList: add (elt): Add element to the end of the list, e.g. arrList.add(elt) get (index): Get an element (with index) in list, e.g. arrList.get(0) size(): Size (total number of elements) of the list, e.g. arrList.size() O o O * Given reference, useful methods for accessing Java class ArrayList: add (elt): Add element to the end of the list, e.g. arrList.add(elt) get (index): Get an element (with index) in list, e.g. arrList.get(0) size(): Size (total number of elements) of the list, e.g. arrList.size() O o

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_2

Step: 3

blur-text-image_3

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

2. What are the different types of networks?

Answered: 1 week ago