Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java language This is a better picture for parts A and B. Question 1 (20 points] Implement the class Country only. The code of the

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Java language

image text in transcribed

This is a better picture for parts A and B.

Question 1 (20 points] Implement the class Country only. The code of the classes Road, Street and Freeway is provided below. Road speedumit: int -length: int carpool: boolean + Road ----All Parameters----) + setters/getters +toString(): String Country - name: String roads: ArrayList + Country(name: String) + getName(): String + getRoads(): ArrayList + addRoad(r: Road): vid + countStreets(): int + searchForStreet((streetName: String): Street + toString(): String Street name: String + Street ----All Parameters----) + setter/getter + toString(): String Freeway code: int + Freeway(----All Parameters----) + setter/getter + toString(): String I + Street ----All Parameters--) + setter/getter + toString(): String + Freeway All Parameters---) + setter/getter + toString(): String A. Implement the class country. Write the following methods: a) A constructor to initialize the name and create the arrayList roads b) The methods getName() and getRoads(). c) The countStreets method that retums the number of streets in the array list. d) The searchForStreet method that takes as parameter the name of a street and returns the street object if found or null if not found e) A toString method to return information about all data fields B. The Road class is characterized by an int speedlimit, a int length, and a boolean carpool. The code is below: public class Road private int speedimiength, private boolean carpool public Road (int speedilimit int length boolean carpool this. speedlimi ekspectinien this.lengthis length this. Carpoo carpool 1/Setters and geltenere mete sume the existir you need aav-ot them. public String tostring 2 return "Road lene hength largeled male 18 needlimit and carpool larga muda na vai labie "not available."); C. The Street class inherits from the class Road. The code is below: public class Street extends Road private String name: public Street (string name, int speedlimit, int length, boolean carpool) super (speedlimit, length, carpool); this.name = name; public String getName() { return name; 3 public void setName (String name) { this.name = name; @Override public String toString() { return "This is " + name + st. " + super.toString(); 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 speedlimit lint length, boolean carpool) { super (speedLimit, length il carpool) : this.code = code public int getCode () return code; } public void setCode (int code) this. code = code, @Override public String tostring()|| return "This is freeway + Code + super.tostring() ; Question 2 [20 points] this. code code: } @Override public String toString() { return "This is freeway" + code + super.toString 03 } Question 2 [20 points] Write a client class (application) in which you: a) Create a country object with name read from the user, and add to the country object some freeways and streets as many as the user wants. b) Write code to display the number of streets in the country object. c) Write code display the information of the country object. d) Test the searchForStreet method by reading a street name from the user and displaying its description if it is available. A. Implement the class country. Write the following methods: a) A constructor to initialize the name and create the arrayList roads. b) The methods getName() and getRoads(). c) The countStreets method that returns the number of streets in the array list. d) The search ForStreet method that takes as parameter the name of a street and returns the street object if found or null if not found. e) A toString method to return information about all data fields. B. The Road class is characterized by an int speed Limit, a int length, and a boolean carpool . The code is below: public class Road / private int speedLimit, length; private boolean carpool; public Road (int speedLimit, int length, boolean carpool) I this.speedLimit speedLimit; this.length = length; this.carpool - carpool; //Setters and getters are skipped here. Assume they exist if you need any of them. public String toString() return "Road length + length + ", speed limit is + speedLimit + " and carpool lane is " + (carpool ? "available. 'not available."); 11

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

More Books

Students also viewed these Databases questions

Question

5. Have you any experience with agile software development?

Answered: 1 week ago