Question
Based on the class BC it y in the last question, write a new Java class named BSFCity for modeling Better Smoke-Free Cities with the
Based on the class BC it y in the last question, write a new Java class named BSFCity for modeling "Better Smoke-Free" Cities with the following requirements.
a) This BSFCity class is a public subclass of the given class BCity.
- This class has a specific instance field of string type, named sFreeRu1e, representing a specific "Smoke-Free" rule governing the "Better Smoke-Free" city.
- It has one constructor with the same set of parameters as its direct superclass.
- The constructor body simply calls the corresponding constructor of its superclass properly.
b) It has 2 public methods:
- The first method setSFreeRu1e ( ) is for setting the specific field, the "Smoke-Free" rule.
- The method accepts one input argument rule of string type and has no return.
- This method body only sets the specific field with the input parameter value.
- The second method overrides the method of its direct superclass for displaying information.
- The method body first calls the overridden method of the superclass.
- The method finally displays an extra line to show the specific "Smoke-Free" rule, as sample program output below.
Sample Program Output
(Suppose the specific "Smoke-Free" rule string is: "LAW of SMOKEFREE ")
City: BSF City, Pop: 8 Rule 21 Rule 22 Smoke-Free Rule : LAW of SMOKE-FREE |
c) This class includes the main method, the entry point for starting the program.
- This main method body first creates an array of City which contains 2 related city objects representing the given two cities listed in the table below.
- This main method then calls the related method to set the smoke-free city object in the array a specific "Smoke-Free" rule string with format: "LAW of "
E.g. "LAW of CHAN Tai Man" if your full name is CHAN Tai Man.
- This main method finally calls the related method to display the smoke-free city object in the array, as sample program output below.
- NO more than 9 statement lines are allowed in the main ( ) method body.
Given Two Cities
Index | Name | Population | Type | List of rules |
0 | "A City" | 2 | City | |
1 | "BSF City" | 8 | BSFCITY | "Rule 21", "Rule 22" |
Sample Program Output
Reference Based on the given references above and the class City in the last question, define a new Java class BC i ty for modeling "Better" Cities with the following requirements.
o This field is initialized with an empty ArrayList of string.
c) It has 2 public methods:
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.
Sample Program Output (Suppose City has: name "B Ci ty", Population 4, Rules: "Rule 11 " and "Rule 12") |
City: BSF City, Pop: 8 Rule 21 Rule 22 Smoke-Free Rule: LAW of CHAN Tai Man 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
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started