I don't really understand the logic behind this question and as a result, I can't really accurately search whether something like this already exists.
Let's say I create a Java class for an object. It only consists of instance variables, getters/setters, and a constructor to create an empty object. For example:
public class Bicycle {
private int speed;
private String model;
public Bicycle(int speed, String model) {
this.speed = speed;
this.model = model;
}
public int getSpeed() {
return speed;
}
public void setSpeed() {
this.speed = speed;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
}
And now let's say I had a text file of bicycles like:
Bike 1234, 60
Bike 333, 50
Bike 555, 20
How would I read the file and then assign each part of the text file to the variables in Bicycle.java?
I want to be able to use the getters and setters in other methods. For example:
public static String searchBikes(int speed, String model) {
if (Bicycle bike.getSpeed().equals(speed) && etc. etc.
I'm unsure as to how to assign each bicycle in the text file to the variables in Bicycle class. Do I need another class (like a database) of sorts? I'm just very lost on this.