Answered step by step
Verified Expert Solution
Question
1 Approved Answer
java Part II: ArrayList and Inheritance [40 points] Question 1 (20 points] Implement the closs Country only. The code of the classes Road, Street and
java
Part II: ArrayList and Inheritance [40 points] Question 1 (20 points] Implement the closs Country only. The code of the classes Road, Street and Freeway is provided below. Country - name: String Road - roads: ArrayList speed Limit: int + Country(name: String) - length: Int * getName(): String - carpool: boolean + getRoads(): ArrayList + Road(---All Parameters. + addRoadr: Road): void + countStreets(): int + setters/getters + searchForStreetf(streetName: String: toString(): String Street toString(): String Street Freeway -name: String - code: Int A. Implement the class + Street (All Parameters-> + Freeway --All Parameters--- country. Write the following + setter/getter ) methods: + toString(): String + setter/getter a) A constructor to initialize roads. +toString(): String the name and create the arrayList b) The methods getNamel) and getRoads(). c) The coutstreets method that retams the number of streets in the array list. di The searchForStreetmethod that takes as parameter the name of a street and returns the street objectif found or null if not found. e) A toString method to return information about all data fields B. The Rond class is characterized by an int speed Limit, a int length, and a boolean carpool. The code is below: public class Road private int speed limit, length private boolean carpooli puble Rond tot speed sit, int length, boolean caipeal) this apeedlinit speedlimit: this. Length - length: this.carpool - carpool + - //Setter and cettes ao atsped here. But they sits ir you need any othe. public string tostring() ! return Roed length length, speed litt is speed.mit. " and carpool lane 15 - carpool ? "available.1 "not available) 1 1 C. The Street class inherits from the class Road. The code is below: Page 4 ofs public class Street extends Road private String name: public Street (String name, int speedlimit, int length, boolean Carpool) { super (speedtimit, length, carpool); this.name = name; ) public String getNamn() { return name; ) public void setName (String name) this.narse - name goverride public String toString() return "This 18" + nano + + + super.tostring(); st. 1 D. The Freeway class inherits from the class Road. The code is below; public class Freeway extends Road private int code: public Freeway (int code, int apuedlimit, int length, boolean carpool) super (speedlimit, length, carpool), this.code - code public int getcode () return code: public void sot Code (int code) this code - code: Overrido public String tostring() { return "This is freeway " + code + super.toString(); . Question 2 [20 points) Write a client class (application) in which you: a) Create a country object with name road from the user, and add to the country object some freeways and streets as many as the user wants b) Writo code to display the number of streets in the country object. c) Write code display the information the country object d) Test the searchForStreet method by reading a street name from the user and displaying its description if it is available Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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