Question
create a class write a java code usig this information is an object representing a metro station with one or more letters indicating its name
create a class write a java code usig this information "is an object representing a metro station with one or more letters indicating its name. For example "A", "BA", "ZTR", etc. Each station has only one link to its next station. (This object should act like a node.) In addition to its name and the link, each station has a number showing its distance (in miles) to the next station."
The problem i am having is what should i write in ToString method
public class Station implements Comparable
public int length;
private String name;
public Station() {
this.length = 2;
}
public Station(int len , String name) {
this.length = len;
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
String dashes = " ";
for (int i = 0; i < this.length; i++) {
dashes += "-";
}
return dashes;
}
}
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