-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned Up Code - Code Renaming of variables
- Loading branch information
1 parent
003c8ee
commit ef7a197
Showing
6 changed files
with
143 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,154 @@ | ||
import java.util.*; | ||
|
||
public class citylist | ||
public class cityList | ||
// This is the class which is made for storing city objects as a list. | ||
{ | ||
ArrayList<city> listofcities; | ||
ArrayList<city> listOfCities; | ||
// This arraylist is the one which has all the city objects. | ||
|
||
citylist() // default constructor. | ||
{ | ||
listofcities = new ArrayList<city>(); // instantiate new ArrayList | ||
cityList() // default constructor. | ||
{ | ||
listOfCities = new ArrayList<city>(); // instantiate new ArrayList | ||
} | ||
|
||
public void append(city a) // Method to append in the list. | ||
{ | ||
listofcities.add(a); | ||
{ | ||
listOfCities.add(a); | ||
} | ||
|
||
/* | ||
contains() Method is used to check if the citylist contains the list or not. | ||
If citylist has the city, then return true, else return false. | ||
We can give parameters of city, city name or coordinates. | ||
*/ | ||
public boolean contains(city a) { | ||
|
||
for (int j = 0; j < listofcities.size(); j++) { | ||
if (city.equals(listofcities.get(j), a) == true) { | ||
* hasCity() Method is used to check if the citylist contains the list or not. | ||
* If citylist has the city, then return true, else return false. | ||
* We can give parameters of city, city name or coordinates. | ||
*/ | ||
public boolean hasCityByCityObj(city a) { | ||
|
||
for (int j = 0; j < listOfCities.size(); j++) { | ||
if (city.equals(listOfCities.get(j), a) == true) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean contains(String a) { | ||
for (int j = 0; j < listofcities.size(); j++) { | ||
if (city.equals(listofcities.get(j), a) == true) { | ||
public boolean hasCityByStringName(String a) { | ||
for (int j = 0; j < listOfCities.size(); j++) { | ||
if (city.equals(listOfCities.get(j), a) == true) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public boolean contains(double a, double b) { | ||
return contains(new city(a, b)); | ||
public boolean hasCityByCoordinates(double a, double b) { | ||
return hasCityByCityObj(new city(a, b)); | ||
} | ||
|
||
public void set(citylist a) | ||
// method to set values of another citylist into this citylist. | ||
{ | ||
listofcities.clear(); | ||
for (int i = 0; i < a.listofcities.size(); i++) { | ||
listofcities.add(a.listofcities.get(i)); | ||
public void copyFromCitylist(cityList a) { | ||
// method to set values of another citylist into this citylist. | ||
|
||
listOfCities.clear(); | ||
for (int i = 0; i < a.listOfCities.size(); i++) { | ||
listOfCities.add(a.listOfCities.get(i)); | ||
} | ||
} | ||
|
||
public city last() // return the last element in the list | ||
{ | ||
return listofcities.get(listofcities.size() - 1); | ||
public city getLastCityElement() { | ||
// return the last element in the list | ||
|
||
return listOfCities.get(listOfCities.size() - 1); | ||
} | ||
|
||
public void pop() // pop from the list | ||
{ | ||
listofcities.remove(listofcities.size() - 1); | ||
{ | ||
listOfCities.remove(listOfCities.size() - 1); | ||
} | ||
|
||
public double sum() | ||
// This method is present to calculate the path length. | ||
// This method sums up the distances between all the two cities in the list. | ||
{ | ||
public double getPathLength() | ||
// This method is present to calculate the path length. | ||
// This method sums up the distances between all the two cities in the list. | ||
{ | ||
double temp = 0; // temparory variable to store the sum. | ||
for (int i = 0; i <= (listofcities.size() - 2); i++) { | ||
temp = | ||
temp + complex.dist(listofcities.get(i).coordinates, listofcities.get(i + 1).coordinates); | ||
for (int i = 0; i <= (listOfCities.size() - 2); i++) { | ||
temp = temp + complex.distanceBetweenComplexPoints(listOfCities.get(i).coordinates, listOfCities.get(i + 1).coordinates); | ||
} | ||
return temp; | ||
} | ||
|
||
/* | ||
Methods to print the elements (name of the cities) of the citylist. | ||
print()- print the names. | ||
println()- print the names on a new line . | ||
print(String Seperator)- print with Seperator, like comma, etc. | ||
*/ | ||
* Methods to print the elements (name of the cities) of the citylist. | ||
* print()- print the names. | ||
* println()- print the names on a new line . | ||
* print(String Seperator)- print with Seperator, like comma, etc. | ||
*/ | ||
public void print() { | ||
for (int i = 0; i <= (listofcities.size() - 1); i++) { | ||
System.out.print(listofcities.get(i).name); | ||
for (int i = 0; i <= (listOfCities.size() - 1); i++) { | ||
System.out.print(listOfCities.get(i).cityName); | ||
} | ||
} | ||
|
||
public void println() { | ||
for (int i = 0; i <= (listofcities.size() - 1); i++) { | ||
System.out.println(listofcities.get(i).name); | ||
for (int i = 0; i <= (listOfCities.size() - 1); i++) { | ||
System.out.println(listOfCities.get(i).cityName); | ||
} | ||
} | ||
|
||
public void print(String Seperator) { | ||
for (int i = 0; i < (listofcities.size() - 1); i++) { | ||
System.out.print(listofcities.get(i).name); | ||
for (int i = 0; i < (listOfCities.size() - 1); i++) { | ||
System.out.print(listOfCities.get(i).cityName); | ||
System.out.print(Seperator); // print with Seperator | ||
} | ||
System.out.print(listofcities.get(listofcities.size() - 1).name); | ||
System.out.print(listOfCities.get(listOfCities.size() - 1).cityName); | ||
} | ||
|
||
/* | ||
posn-The method to find the position of the city in the list. | ||
Can add parameters of city object, city name or coordinates. | ||
*/ | ||
public int posn(city a) { | ||
for (int j = 0; j < listofcities.size(); j++) { | ||
if (city.equals(listofcities.get(j), a) == true) { | ||
* The methods to find the position of the city in the list. | ||
* Can add parameters of city object, city name or coordinates. | ||
*/ | ||
public int getPositionByCity(city a) { | ||
for (int j = 0; j < listOfCities.size(); j++) { | ||
if (city.equals(listOfCities.get(j), a) == true) { | ||
return j; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public int posn(String a) { | ||
for (int j = 0; j < listofcities.size(); j++) { | ||
if (city.equals(listofcities.get(j), a) == true) { | ||
public int getPositionByString(String a) { | ||
for (int j = 0; j < listOfCities.size(); j++) { | ||
if (city.equals(listOfCities.get(j), a) == true) { | ||
return j; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public int posn(double a, double b) { | ||
return posn(new city(a, b)); | ||
public int getPositionByPoint(double a, double b) { | ||
return getPositionByCity(new city(a, b)); | ||
} | ||
|
||
/* | ||
Method to get the city object from the citylist. | ||
*/ | ||
public city get(int a) // get the a'th position of the citylist | ||
{ | ||
return listofcities.get(a); | ||
* Methods to get the city object from the citylist. | ||
*/ | ||
public city getCityByPosition(int a) // get the a'th position of the citylist | ||
{ | ||
return listOfCities.get(a); | ||
} | ||
|
||
public city get(city a) { | ||
return get(posn(a)); | ||
public city getCityByCity(city a) { | ||
return getCityByPosition(getPositionByCity(a)); | ||
} | ||
|
||
public city get(String a) { | ||
return listofcities.get(posn(a)); | ||
public city getCityByCityName(String a) { | ||
return listOfCities.get(getPositionByString(a)); | ||
} | ||
|
||
public city get(double a, double b) { | ||
return get(new city(a, b)); | ||
public city getCityByCoordinates(double a, double b) { | ||
return getCityByCity(new city(a, b)); | ||
} | ||
|
||
public int size() // the size of the citylist | ||
{ | ||
return listofcities.size(); | ||
public int getSizeOfCityList() // the size of the citylist | ||
{ | ||
return listOfCities.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.