I have record which is called Station and I created 3 instances of the object. They are named for different stations. I wish to have the user enter the name of the station they want to know more about and it shows the user the information about that station.
However when I use my getter method to obtain the information because the user input is a string and the getter method wants the station object in order to function, what is the best process for achieving this while staying expandable (Being able to add more stations on the fly).
My code is as follows:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Station Reading = CreateStation("Reading", "Great Western", true);
Station Bristol = CreateStation("Bristol", "Great Western", false);
Station York = CreateStation("York", "Great Eastern", true);
System.out.println("What Station do you need to know about? ");
String UsrStation = s.nextLine();
System.out.println(staGetName(York)+" "+staGetOp(York)+" "+staGetStep(York));
}
public static Station CreateStation(String StationName, String Operator, Boolean StepFree){
Station s = new Station();
staSetName(s, StationName);
staSetOp(s, Operator);
staSetStep(s, StepFree);
return s;
}
//Getter Methods for Station
public static String staGetName(Station s){
return s.name;
}
public static String staGetOp(Station s){
return s.operator;
}
public static Boolean staGetStep(Station s){
return s.stepFree;
}
//Setter Methods for Station
public static Station staSetName(Station s, String name){
s.name = name;
return s;
}
public static Station staSetOp(Station s, String operator){
s.operator = operator;
return s;
}
public static Station staSetStep(Station s, Boolean stepFree){
s.stepFree = stepFree;
return s;
}
}
class Station{
String name;
String operator;
Boolean stepFree;
}
Sorry if this is simple, or bad practice. I am only just learning!