The first couple of bullet points has already been completed, i just need help w
ID: 3675441 • Letter: T
Question
The first couple of bullet points has already been completed, i just need help with displaybyWheelchair(), and displayDistance()
Here is a link to the current Java code that I have written for this problem
CTAStopApp : https://www.dropbox.com/s/87y67j9u4fltjje/CTAStopApp.java?dl=0
CTAStation: https://www.dropbox.com/s/wkmlt0snspwwwe0/CTAStation.java?dl=0
GeoLocation: https://www.dropbox.com/s/ufauedegtdlx83a/GeoLocation.java?dl=0
the csv file I'm reading from in my code : https://www.dropbox.com/s/c4ck911rm8c310o/greenLineStops.csv?dl=0
Can someone help to edit my current CTAStopApp code to, if the number 2 is pressed on the menu I want to display which stops are wheelchair accessible whether the user enters y or n. ( I can't get this part to work correctly)
Also, if the number 3 is pressed the user should be prompted to enter a latitude or longitude "(double, double)" which whill then call the distance code I wrote and return the stations within the specified latitude/longitude range
CTAStopApp As mentioned earlier, this app will display a menu of options of which data to extract from the data stored in the CTAStationl. The API for this app class is as below: You do not need to follow this API but it may help you to figure out how to break down the tasks. . main) reads station input file and stores the data in an instance of CTAStationl . displays the menu options, which should be the following: . Display Station Names . Display Stations with/without Wheelchair AccessExplanation / Answer
package Lab5;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class CTAStopApp extends CTAStation
{
public static CTAStation[] cta_station = new CTAStation[27];
public static void displayNames(){
System.out.println("---- Station Names ----");
for(int i=0; i<cta_station.length; i++){
System.out.println(cta_station[i].name);
}
}
public static void displayWheel(char ch)
{ CTAStopApp c=new CTAStation();
if(ch == 'y' || ch == 'Y'){
System.out.println("---- Station w/ Wheel Chair Accessibility ----");
boolean check = false;
for (int i=0; i<cta_station.length; i++){
if (c.isWheelchair() == true)
{
System.out.println(cta_station[i].name);
check =true;
}
}
} else {
System.out.println("---- Station w/o Wheel Chair Accessibility ----");
boolean check = false;
for (int i=0; i<cta_station.length; i++){
if (c.isWheelChair == false){
System.out.println(cta_station[i].name);
check =true;
}
} if (check ==false)
System.out.println("No such station found");
}
}
public void getDistance(double latitude, double longitude)
{
CTAStation c= new GeoLocation ();
double distance=c.calDistance(latitude,longitude);
for (int i=0; i<cta_station.length; i++)
{
if(c.equals(GeoLocation g) == true)
System.out.println(cta_station[i].name);
}
}
public static void main(String[] args){
//Reading in data from file
BufferedReader br = null;
try{
br = new BufferedReader(new FileReader("C:/Users/Devonald/Downloads/greenLineStops.csv"));
int i = 0;
String line;
while((line = br.readLine())!=null){
//Using comma as separator
String[] temp = line.split(",");
String name = temp[0];
String location = temp[3];
boolean opened = (temp[4].compareTo("TRUE")==0)? true:false;
double latitude = Double.parseDouble(temp[1]);
double longitude = Double.parseDouble(temp[2]);
boolean wheelchair = (temp[5].compareTo("TRUE")==0)? true:false;
CTAStation ct = new CTAStation(name,location,opened,latitude,longitude,wheelchair);
cta_station[i] = ct;
i += 1;
}
//Display Menu option
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("1. Display Station Names");
System.out.println("2. Display Station with/without Wheel Chair Access");
System.out.println("3. Display the distance to each station");
System.out.println("4. Exit Options");
int n = sc.nextInt();
if(n==1)
displayNames();
else if(n==2){
System.out.print("Enter accessibility (y or n only): ");
char ch = sc.next().charAt(0);
if (ch!= 'Y' || ch != 'y' || ch != 'n' || ch != 'N'){
System.out.print("Enter accessibility (Y OR N ONLY): ");
ch = sc.next().charAt(0);
}
displayWheel(ch);
}
else if(n==3){
System.out.println("enter latitude and longitude");
double dist= getDistance();
}
else break;
}
}
catch (FileNotFoundException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
}
}
Code2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package Lab5;
public class CTAStation extends GeoLocation{
protected String name;
protected String location;
protected boolean opened;
protected double latitude;
protected double longitude;
protected boolean wheelchair;
public CTAStation(){
super();
name = "Green Line";
location = "Location";
opened = false;
wheelchair = false;
}
public CTAStation(String name, String location, boolean opened, double latitude, double longitude, boolean wheelchair){
this.name = name;
this.location = location;
this.opened = opened;
this.latitude = latitude;
this.longitude = longitude;
this.wheelchair = wheelchair;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public boolean isOpened() {
return opened;
}
public void setOpened(boolean opened) {
this.opened = opened;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public boolean isWheelchair() {
return wheelchair;
}
public void setWheelchair(boolean wheelchair) {
this.wheelchair = wheelchair;
}
public String toString(){
return "The CTAStation information is as follows, Name: " + name + "Location: " + location + "Open: "
+ opened + "Latitude: " + latitude + "Longitude: " + longitude + "Wheelchair: " + wheelchair;
}
public boolean equals(GeoLocation g){
if(((CTAStation)g).getLatitude()!=latitude){
return false;
} else if (((CTAStation)g).getLongitude()!=longitude){
return false;
}
return true;
}
public double calcDistance(CTAStation c){
return Math.sqrt(Math.pow(c.getLatitude()-latitude,2) + Math.pow(c.getLongitude()-longitude,2));
}
public double calcDistance(double latitude, double longitude){
return Math.sqrt(Math.pow(latitude-getLatitude(),2) + Math.pow(longitude-getLongitude(),2));
}
}
code 3:
package Lab5;
public class GeoLocation {
protected double latitude;
protected double longitude;
public GeoLocation(){
latitude = 0;
longitude = 0;
}
public GeoLocation(double latitude, double longitude){
this.latitude = latitude;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public String toString(){
return "Latitude: " + latitude + "Longitude : " + longitude;
}
public boolean equals (GeoLocation g){
if(Math.abs(g.getLatitude()-latitude)>0.001){
return false;
} else if (Math.abs(g.getLongitude()-longitude)>0.001){
return false;
}
return true;
}
public double calcDistance(GeoLocation g){
return Math.sqrt(Math.pow(g.getLatitude()-latitude,2) + Math.pow(g.getLongitude()-longitude,2));
}
public double calcDistance(double latitude, double longitude){
return Math.sqrt(Math.pow(latitude-getLatitude(),2) + Math.pow(longitude-getLongitude(),2));
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package Lab5;
public class CTAStation extends GeoLocation{
protected String name;
protected String location;
protected boolean opened;
protected double latitude;
protected double longitude;
protected boolean wheelchair;
public CTAStation(){
super();
name = "Green Line";
location = "Location";
opened = false;
wheelchair = false;
}
public CTAStation(String name, String location, boolean opened, double latitude, double longitude, boolean wheelchair){
this.name = name;
this.location = location;
this.opened = opened;
this.latitude = latitude;
this.longitude = longitude;
this.wheelchair = wheelchair;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public boolean isOpened() {
return opened;
}
public void setOpened(boolean opened) {
this.opened = opened;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public boolean isWheelchair() {
return wheelchair;
}
public void setWheelchair(boolean wheelchair) {
this.wheelchair = wheelchair;
}
public String toString(){
return "The CTAStation information is as follows, Name: " + name + "Location: " + location + "Open: "
+ opened + "Latitude: " + latitude + "Longitude: " + longitude + "Wheelchair: " + wheelchair;
}
public boolean equals(GeoLocation g){
if(((CTAStation)g).getLatitude()!=latitude){
return false;
} else if (((CTAStation)g).getLongitude()!=longitude){
return false;
}
return true;
}
public double calcDistance(CTAStation c){
return Math.sqrt(Math.pow(c.getLatitude()-latitude,2) + Math.pow(c.getLongitude()-longitude,2));
}
public double calcDistance(double latitude, double longitude){
return Math.sqrt(Math.pow(latitude-getLatitude(),2) + Math.pow(longitude-getLongitude(),2));
}
}
code 3:
package Lab5;
public class GeoLocation {
protected double latitude;
protected double longitude;
public GeoLocation(){
latitude = 0;
longitude = 0;
}
public GeoLocation(double latitude, double longitude){
this.latitude = latitude;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public String toString(){
return "Latitude: " + latitude + "Longitude : " + longitude;
}
public boolean equals (GeoLocation g){
if(Math.abs(g.getLatitude()-latitude)>0.001){
return false;
} else if (Math.abs(g.getLongitude()-longitude)>0.001){
return false;
}
return true;
}
public double calcDistance(GeoLocation g){
return Math.sqrt(Math.pow(g.getLatitude()-latitude,2) + Math.pow(g.getLongitude()-longitude,2));
}
public double calcDistance(double latitude, double longitude){
return Math.sqrt(Math.pow(latitude-getLatitude(),2) + Math.pow(longitude-getLongitude(),2));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.