I am assuming you are doing something like this:
Your Patient Class:
public class Patient {
private String patientID;
public Patient(String patientID) {
this.patientID = patientID;
}
public String getPatientID() {
return patientID;
}
public void setPatientID(String patientID) {
this.patientID = patientID;
}
}
...and your class that you are using for running the console:
public class Main {
public Main() {
}
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("System is ready to accept input, please enter ID : ");
String ID = console.nextLine();
Patient patient = new Patient(ID);
//do some fancy stuff with your patient
}
}
This would be a very basic example.
As you are learning to code, be sure to really think about how to name your classes. Calling your class "Patients" would make me expect you are holding a collection of "Patients" inside each instance of this java class, rather than a single "Patient" per instance.
Regarding the latest answers including Maps, the updated "Main" class could look like this:
public class Main {
static Map<String, Patient> patients = new HashMap<String, Patient>();
public Main() {
}
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("System is ready to accept input, please enter ID : ");
String id = console.nextLine();
patients.put(id, new Patient(id));
}
}