So I'm creating a student database thing for a school project. My first issue is that upon creating a new student I should see "Application number ### has registered successfully". Now the problem is that we have to have that number generate (### referring to the number) sequentially from 1 every time a new application is recorded. How would I go about doing that?
So far this is what there is but I can't seem to get the number to generate incrementally.
public TestApplication(String Surname, String personalIdNo)
{
if (isValidpersonalIdNo(personalIdNo) == true)
{
Student.add(Surname);
Application.put(personalIdNo, Student);
System.out.println("Application number ### " + "has registered successfully");
}
else
{
System.out.println("Application has failed, Personal id: " + personalIdNo);
}
}
Any help with this would be appreicated.
AtomicLongmay be interesting. For the latter, just use DB-generated PK (in e.g. MySQL, check its documentation using keyword "auto_increment")String surName(orsurname). Per java convention, instances should be camelCased. Second, for your second parameter, useintorIntegerfor a numeric field.int applicationNumber = 0as an instance variable. And then you can incrementapplicationNumber++on application registration method call.