Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

B4. (15 marks) * Students should finish reading the whole question first, before answering. - Given reference, useful methods for accessing Java class ArrayList: add

image text in transcribed

B4. (15 marks) * Students should finish reading the whole question first, before answering. - Given reference, useful methods for accessing Java class ArrayList: add (alt): Add element to the end of the list, e arst.add(elt) get (index): Get an element (with index) in list e arrestiget (0) size(): Size (total number of clements) of the list.cg. artist.size() Based on the given references above and the class city in the last question, define a new Java class city for modeling "Better" Cities with the following requirements. a) This BCity class is a public subclass of the given class City 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, This field is initialized with an empty ArrayList of string. (4 marks/ b) It has one constructor with 3 parameters (String ON, int ce, String[] rules): 0 The first and second parameters are for the name and population of the city object, while the third parameter is for the rules. The body of this constructor first calls the corresponding constructor of its superclass with the two related input parameters The constructor body then adds all elements of the input array parameter into its own specific field Rust 14 marks O o c) It has 2 public methods: The method hasRule() is for checking if the city includes a specific rule string. 0 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 bruit 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 The method dispruit() is for displaying information of the object on console The method has ne 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) ay sumple programomiw below o IS Sample Program Opel Suppose City has nume "City Population, Rideale and "Rule 12 City City. Pop: 4 Rule 1 Rule 1 mark

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 is a legacy system and what is its relevance to CRM?

Answered: 1 week ago