Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this program: Create the City and Road classes as specified in the tables be

ID: 3741464 • Letter: F

Question


For this program:
Create the City and Road classes as specified in the tables below.
In the main method of the NCCitiesRoads class
Create 6 City vertices and add them to an ArrayList using the details given below in the table
Create 18 Road edges between the cities and add them to an ArrayList using the details given below in the table.
Create a WeightedGraph with City vertices and Road edges.
Be sure to follow the constructors for the City, the Road, and the WeightedGraph classes when creating the objects.
Next, display each of the items requested below:
The number of Cities in the map.
The City object information for the 4th City added, using a graph method to retrieve the City.
The City with the largest number of Roads ending there.
The Road edge information for each Road using a graph method.
The complete Road information for each Road from the Road ArrayList. Cast the WeightedEdge to a Road object.
Provide an additional ArrayList with the Cities sorted and print it – Use the Collections.sort method.
Table 1: City Class
Class City implements Comparable<City>
Private Instance Variables
Description
String city
City name
double gpsX
GPS Longitude in Decimal Degrees
double gpsY
GPS Latitude in Decimal Degrees
int population
Population
int vertIndex
Index in Vertex ArrayList
Public Instance Methods
Description
City (String name, double x,
double y, int size,
int index)
Constructor to initialize each instance variable. Do not round these numbers, here – do the rounding in printCity().
String getCity()
Getter for city
double getLongitude()
Getter for gpsX
double getLatitude()
Getter for gpsY
int getPopulation()
Getter for population
int getIndex()
Getter for vertIndex
void setIndex (int index)
Setter for vertIndex
int compareTo (City c)
Compares population
boolean equals (Object c)
Override equals comparing city name
String toString()
Return City name
String printCity()
Return City object information with the GPS coordinates rounded to 2 decimal places, as
Mars Hill: [1]:[-82.55, 35.83]:(1869)
Table 2: Road Class
Class Road extends WeightedEdge
implements Comparable< WeightedEdge>
Private Instance Vars
Description
City startCity
City at (x1, y1)
City endCity
City at (x2, y2)
double distance
Miles from startCity to endCity as crow flies
String direction
Map direction: N, S, E, W, etc
Public Instance Methods
Description
Road (City c1, City c2)
Constructor to initialize each instance variable:
double getDistance()
Getter for distance
String getDirection()
Getter for direction
int compareTo (Road r)
Compares distance between startCity and endCity; the weight
String toString()
Return City names at either end of Road String printRoad()
Return Road object information with the distance rounded to 2 decimal places For example: Gastonia to Hickory traveling N for 34.84 miles
Private Instance Methods
Description
int findQuadrant
(double x1, double y1,
double x2, double y2)
Return the quadrant in which the direction of travel takes you from PointA (x1,y1) (startCity) to PointB:(x2,y2) (endCity): return 1, 2, 3, or 4 double compAngle
(double sideA,
double sideB,
double sideC)
Return the angle at PointA: (x1,y1) in degrees: where sideA is across from PointA: (x1,y1), side B is across from PointB: (x2,y2) and sideC is the path from PointA to PointB double distance
(double x1, double y1, double x2, double y2)
Return the distance from (x1,y1) to (x2,y2) DO NOT round the answer here
String compDirection
(double angle, int quad)
Return the direction of travel using angle and quadrant void computeDirection
()
Called from the constructor; use all the other private instance methods and City instance variables to set the values of the the distance and direction instance variables for the Road object. You must start this function by changing the GPS coordinates to radians. At the end of the method change the distance to miles before storing it. (multiply by 3956). Table 3: City Information
City
Longitude
Latitude
Population
Murphy
-84.029924
35.089848
1627
Mars Hill
-82.547843
35.828496
1869
Mooresville
-80.820139
35.584337
32711
Morrisville
-78.828930
35.827493
18576
Morehead City
-76.746748
34.727700
8661
Manteo
-75.669385
35.904595
1434
Table 4: Road Information
City1
City2
City1
City2
0
Murphy
Mars Hill
3
Morrisville
Mars Hill
0
Murphy
Mooresville
3
Morrisville
Mooresville
1
Mars Hill
Murphy
3
Morrisville
Morehead City
1
Mars Hill
Mooresville
3
Morrisville
Manteo
1
Mars Hill
Morrisville
4
Morehead City
Mooresville
2
Mooresville
Murphy
4
Morehead City
Morrisville
2
Mooresville
Mars Hill
4
Morehead City
Manteo
2
Mooresville
Morrisville
5
Manteo
Morrisville
2
Mooresville
Morehead City
5
Manteo
Morehead City
Sample Output:
The number of cities: 6
The fourth city added: Morrisville: [3]:[-78.83, 35.83]:(18576)
The city with most roads: Mooresville
Weighted Edge (Road) information:
Murphy (0):
(0, 1, 114.34) (0, 2, 224.23)
Mars Hill (1):
(1, 0, 114.34) (1, 2, 120.48) (1, 3, 256.77)
Mooresville (2):
(2, 0, 224.23) (2, 1, 120.48) (2, 3, 138.5) (2, 4, 287.4)
Morrisville (3):
(3, 1, 256.77) (3, 2, 138.5) (3, 4, 162.59) (3, 5, 218.22)
Morehead City (4):
(4, 2, 287.4) (4, 3, 162.59) (4, 5, 110.17)
Manteo (5):
(5, 3, 218.22) (5, 4, 110.17)
Complete Road information:
Murphy to Mars Hill traveling ENE for 114.34 miles
Murphy to Mooresville traveling E for 224.23 miles
Mars Hill to Murphy traveling WSW for 114.34 miles
Mars Hill to Mooresville traveling E for 120.48 miles
Mars Hill to Morrisville traveling E for 256.77 miles
Mooresville to Murphy traveling W for 224.23 miles
Mooresville to Mars Hill traveling W for 120.48 miles
Mooresville to Morrisville traveling E for 138.5 miles
Mooresville to Morehead City traveling ESE for 287.4 miles
Morrisville to Mars Hill traveling W for 256.77 miles
Morrisville to Mooresville traveling W for 138.5 miles
Morrisville to Morehead City traveling ESE for 162.59 miles
Morrisville to Manteo traveling E for 218.22 miles
Morehead City to Mooresville traveling WNW for 287.4 miles
Morehead City to Morrisville traveling WNW for 162.59 miles
Morehead City to Manteo traveling NE for 110.17 miles
Manteo to Morrisville traveling W for 218.22 miles
Manteo to Morehead City traveling SW for 110.17 miles
Cities sorted by size:
Manteo: [5]:[-75.67, 35.9]:(1434)
Murphy: [0]:[-84.03, 35.09]:(1627)
Mars Hill: [1]:[-82.55, 35.83]:(1869)
Morehead City: [4]:[-76.75, 34.73]:(8661)
Morrisville: [3]:[-78.83, 35.83]:(18576)
Mooresville: [2]:[-80.82, 35.58]:(32711)
For this program:
Create the City and Road classes as specified in the tables below.
In the main method of the NCCitiesRoads class
Create 6 City vertices and add them to an ArrayList using the details given below in the table
Create 18 Road edges between the cities and add them to an ArrayList using the details given below in the table.
Create a WeightedGraph with City vertices and Road edges.
Be sure to follow the constructors for the City, the Road, and the WeightedGraph classes when creating the objects.
Next, display each of the items requested below:
The number of Cities in the map.
The City object information for the 4th City added, using a graph method to retrieve the City.
The City with the largest number of Roads ending there.
The Road edge information for each Road using a graph method.
The complete Road information for each Road from the Road ArrayList. Cast the WeightedEdge to a Road object.
Provide an additional ArrayList with the Cities sorted and print it – Use the Collections.sort method.
Table 1: City Class
Class City implements Comparable<City>
Private Instance Variables
Description
String city
City name
double gpsX
GPS Longitude in Decimal Degrees
double gpsY
GPS Latitude in Decimal Degrees
int population
Population
int vertIndex
Index in Vertex ArrayList
Public Instance Methods
Description
City (String name, double x,
double y, int size,
int index)
Constructor to initialize each instance variable. Do not round these numbers, here – do the rounding in printCity().
String getCity()
Getter for city
double getLongitude()
Getter for gpsX
double getLatitude()
Getter for gpsY
int getPopulation()
Getter for population
int getIndex()
Getter for vertIndex
void setIndex (int index)
Setter for vertIndex
int compareTo (City c)
Compares population
boolean equals (Object c)
Override equals comparing city name
String toString()
Return City name
String printCity()
Return City object information with the GPS coordinates rounded to 2 decimal places, as
Mars Hill: [1]:[-82.55, 35.83]:(1869)
Table 2: Road Class
Class Road extends WeightedEdge
implements Comparable< WeightedEdge>
Private Instance Vars
Description
City startCity
City at (x1, y1)
City endCity
City at (x2, y2)
double distance
Miles from startCity to endCity as crow flies
String direction
Map direction: N, S, E, W, etc
Public Instance Methods
Description
Road (City c1, City c2)
Constructor to initialize each instance variable:
double getDistance()
Getter for distance
String getDirection()
Getter for direction
int compareTo (Road r)
Compares distance between startCity and endCity; the weight
String toString()
Return City names at either end of Road String printRoad()
Return Road object information with the distance rounded to 2 decimal places For example: Gastonia to Hickory traveling N for 34.84 miles
Private Instance Methods
Description
int findQuadrant
(double x1, double y1,
double x2, double y2)
Return the quadrant in which the direction of travel takes you from PointA (x1,y1) (startCity) to PointB:(x2,y2) (endCity): return 1, 2, 3, or 4 double compAngle
(double sideA,
double sideB,
double sideC)
Return the angle at PointA: (x1,y1) in degrees: where sideA is across from PointA: (x1,y1), side B is across from PointB: (x2,y2) and sideC is the path from PointA to PointB double distance
(double x1, double y1, double x2, double y2)
Return the distance from (x1,y1) to (x2,y2) DO NOT round the answer here
String compDirection
(double angle, int quad)
Return the direction of travel using angle and quadrant void computeDirection
()
Called from the constructor; use all the other private instance methods and City instance variables to set the values of the the distance and direction instance variables for the Road object. You must start this function by changing the GPS coordinates to radians. At the end of the method change the distance to miles before storing it. (multiply by 3956). Table 3: City Information
City
Longitude
Latitude
Population
Murphy
-84.029924
35.089848
1627
Mars Hill
-82.547843
35.828496
1869
Mooresville
-80.820139
35.584337
32711
Morrisville
-78.828930
35.827493
18576
Morehead City
-76.746748
34.727700
8661
Manteo
-75.669385
35.904595
1434
Table 4: Road Information
City1
City2
City1
City2
0
Murphy
Mars Hill
3
Morrisville
Mars Hill
0
Murphy
Mooresville
3
Morrisville
Mooresville
1
Mars Hill
Murphy
3
Morrisville
Morehead City
1
Mars Hill
Mooresville
3
Morrisville
Manteo
1
Mars Hill
Morrisville
4
Morehead City
Mooresville
2
Mooresville
Murphy
4
Morehead City
Morrisville
2
Mooresville
Mars Hill
4
Morehead City
Manteo
2
Mooresville
Morrisville
5
Manteo
Morrisville
2
Mooresville
Morehead City
5
Manteo
Morehead City
Sample Output:
The number of cities: 6
The fourth city added: Morrisville: [3]:[-78.83, 35.83]:(18576)
The city with most roads: Mooresville
Weighted Edge (Road) information:
Murphy (0):
(0, 1, 114.34) (0, 2, 224.23)
Mars Hill (1):
(1, 0, 114.34) (1, 2, 120.48) (1, 3, 256.77)
Mooresville (2):
(2, 0, 224.23) (2, 1, 120.48) (2, 3, 138.5) (2, 4, 287.4)
Morrisville (3):
(3, 1, 256.77) (3, 2, 138.5) (3, 4, 162.59) (3, 5, 218.22)
Morehead City (4):
(4, 2, 287.4) (4, 3, 162.59) (4, 5, 110.17)
Manteo (5):
(5, 3, 218.22) (5, 4, 110.17)
Complete Road information:
Murphy to Mars Hill traveling ENE for 114.34 miles
Murphy to Mooresville traveling E for 224.23 miles
Mars Hill to Murphy traveling WSW for 114.34 miles
Mars Hill to Mooresville traveling E for 120.48 miles
Mars Hill to Morrisville traveling E for 256.77 miles
Mooresville to Murphy traveling W for 224.23 miles
Mooresville to Mars Hill traveling W for 120.48 miles
Mooresville to Morrisville traveling E for 138.5 miles
Mooresville to Morehead City traveling ESE for 287.4 miles
Morrisville to Mars Hill traveling W for 256.77 miles
Morrisville to Mooresville traveling W for 138.5 miles
Morrisville to Morehead City traveling ESE for 162.59 miles
Morrisville to Manteo traveling E for 218.22 miles
Morehead City to Mooresville traveling WNW for 287.4 miles
Morehead City to Morrisville traveling WNW for 162.59 miles
Morehead City to Manteo traveling NE for 110.17 miles
Manteo to Morrisville traveling W for 218.22 miles
Manteo to Morehead City traveling SW for 110.17 miles
Cities sorted by size:
Manteo: [5]:[-75.67, 35.9]:(1434)
Murphy: [0]:[-84.03, 35.09]:(1627)
Mars Hill: [1]:[-82.55, 35.83]:(1869)
Morehead City: [4]:[-76.75, 34.73]:(8661)
Morrisville: [3]:[-78.83, 35.83]:(18576)
Mooresville: [2]:[-80.82, 35.58]:(32711)
For this program:
Create the City and Road classes as specified in the tables below.
In the main method of the NCCitiesRoads class
Create 6 City vertices and add them to an ArrayList using the details given below in the table
Create 18 Road edges between the cities and add them to an ArrayList using the details given below in the table.
Create a WeightedGraph with City vertices and Road edges.
Be sure to follow the constructors for the City, the Road, and the WeightedGraph classes when creating the objects.
Next, display each of the items requested below:
The number of Cities in the map.
The City object information for the 4th City added, using a graph method to retrieve the City.
The City with the largest number of Roads ending there.
The Road edge information for each Road using a graph method.
The complete Road information for each Road from the Road ArrayList. Cast the WeightedEdge to a Road object.
Provide an additional ArrayList with the Cities sorted and print it – Use the Collections.sort method.
Table 1: City Class
Class City implements Comparable<City>
Private Instance Variables
Description
String city
City name
double gpsX
GPS Longitude in Decimal Degrees
double gpsY
GPS Latitude in Decimal Degrees
int population
Population
int vertIndex
Index in Vertex ArrayList
Public Instance Methods
Description
City (String name, double x,
double y, int size,
int index)
Constructor to initialize each instance variable. Do not round these numbers, here – do the rounding in printCity().
String getCity()
Getter for city
double getLongitude()
Getter for gpsX
double getLatitude()
Getter for gpsY
int getPopulation()
Getter for population
int getIndex()
Getter for vertIndex
void setIndex (int index)
Setter for vertIndex
int compareTo (City c)
Compares population
boolean equals (Object c)
Override equals comparing city name
String toString()
Return City name
String printCity()
Return City object information with the GPS coordinates rounded to 2 decimal places, as
Mars Hill: [1]:[-82.55, 35.83]:(1869)
Table 2: Road Class
Class Road extends WeightedEdge
implements Comparable< WeightedEdge>
Private Instance Vars
Description
City startCity
City at (x1, y1)
City endCity
City at (x2, y2)
double distance
Miles from startCity to endCity as crow flies
String direction
Map direction: N, S, E, W, etc
Public Instance Methods
Description
Road (City c1, City c2)
Constructor to initialize each instance variable:
double getDistance()
Getter for distance
String getDirection()
Getter for direction
int compareTo (Road r)
Compares distance between startCity and endCity; the weight
String toString()
Return City names at either end of Road String printRoad()
Return Road object information with the distance rounded to 2 decimal places For example: Gastonia to Hickory traveling N for 34.84 miles
Private Instance Methods
Description
int findQuadrant
(double x1, double y1,
double x2, double y2)
Return the quadrant in which the direction of travel takes you from PointA (x1,y1) (startCity) to PointB:(x2,y2) (endCity): return 1, 2, 3, or 4 double compAngle
(double sideA,
double sideB,
double sideC)
Return the angle at PointA: (x1,y1) in degrees: where sideA is across from PointA: (x1,y1), side B is across from PointB: (x2,y2) and sideC is the path from PointA to PointB double distance
(double x1, double y1, double x2, double y2)
Return the distance from (x1,y1) to (x2,y2) DO NOT round the answer here
String compDirection
(double angle, int quad)
Return the direction of travel using angle and quadrant void computeDirection
()
Called from the constructor; use all the other private instance methods and City instance variables to set the values of the the distance and direction instance variables for the Road object. You must start this function by changing the GPS coordinates to radians. At the end of the method change the distance to miles before storing it. (multiply by 3956). Table 3: City Information
City
Longitude
Latitude
Population
Murphy
-84.029924
35.089848
1627
Mars Hill
-82.547843
35.828496
1869
Mooresville
-80.820139
35.584337
32711
Morrisville
-78.828930
35.827493
18576
Morehead City
-76.746748
34.727700
8661
Manteo
-75.669385
35.904595
1434
Table 4: Road Information
City1
City2
City1
City2
0
Murphy
Mars Hill
3
Morrisville
Mars Hill
0
Murphy
Mooresville
3
Morrisville
Mooresville
1
Mars Hill
Murphy
3
Morrisville
Morehead City
1
Mars Hill
Mooresville
3
Morrisville
Manteo
1
Mars Hill
Morrisville
4
Morehead City
Mooresville
2
Mooresville
Murphy
4
Morehead City
Morrisville
2
Mooresville
Mars Hill
4
Morehead City
Manteo
2
Mooresville
Morrisville
5
Manteo
Morrisville
2
Mooresville
Morehead City
5
Manteo
Morehead City
Sample Output:
The number of cities: 6
The fourth city added: Morrisville: [3]:[-78.83, 35.83]:(18576)
The city with most roads: Mooresville
Weighted Edge (Road) information:
Murphy (0):
(0, 1, 114.34) (0, 2, 224.23)
Mars Hill (1):
(1, 0, 114.34) (1, 2, 120.48) (1, 3, 256.77)
Mooresville (2):
(2, 0, 224.23) (2, 1, 120.48) (2, 3, 138.5) (2, 4, 287.4)
Morrisville (3):
(3, 1, 256.77) (3, 2, 138.5) (3, 4, 162.59) (3, 5, 218.22)
Morehead City (4):
(4, 2, 287.4) (4, 3, 162.59) (4, 5, 110.17)
Manteo (5):
(5, 3, 218.22) (5, 4, 110.17)
Complete Road information:
Murphy to Mars Hill traveling ENE for 114.34 miles
Murphy to Mooresville traveling E for 224.23 miles
Mars Hill to Murphy traveling WSW for 114.34 miles
Mars Hill to Mooresville traveling E for 120.48 miles
Mars Hill to Morrisville traveling E for 256.77 miles
Mooresville to Murphy traveling W for 224.23 miles
Mooresville to Mars Hill traveling W for 120.48 miles
Mooresville to Morrisville traveling E for 138.5 miles
Mooresville to Morehead City traveling ESE for 287.4 miles
Morrisville to Mars Hill traveling W for 256.77 miles
Morrisville to Mooresville traveling W for 138.5 miles
Morrisville to Morehead City traveling ESE for 162.59 miles
Morrisville to Manteo traveling E for 218.22 miles
Morehead City to Mooresville traveling WNW for 287.4 miles
Morehead City to Morrisville traveling WNW for 162.59 miles
Morehead City to Manteo traveling NE for 110.17 miles
Manteo to Morrisville traveling W for 218.22 miles
Manteo to Morehead City traveling SW for 110.17 miles
Cities sorted by size:
Manteo: [5]:[-75.67, 35.9]:(1434)
Murphy: [0]:[-84.03, 35.09]:(1627)
Mars Hill: [1]:[-82.55, 35.83]:(1869)
Morehead City: [4]:[-76.75, 34.73]:(8661)
Morrisville: [3]:[-78.83, 35.83]:(18576)
Mooresville: [2]:[-80.82, 35.58]:(32711)

Explanation / Answer

String getCity()

Getter for city

double getLongitude()

Getter for gpsX

double getLatitude()

Getter for gpsY

int getPopulation()

Getter for population

int getIndex()

Getter for vertIndex

void setIndex (int index)

Setter for vertIndex

int compareTo (City c)

Compares population

boolean equals (Object c)

Override equals comparing city name

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote