So I have an issue with Hashmaps and a login feature.
When using addLogin I am required to enter parameters but it makes no sense to do this since I have already done this in the constructor classes. How would I simply just use addLogin and the Surname, Forename and Personal ID number is added to the hashmap?
Upon using Math.round(Math.random()*999+1) to generate a random number between 1-999 how am I supposed to go around adding this to the hashmap with the other student details?
Here is the full code that applies to both questions, apologies for the stupid questions I'm very new to Java! I am very appreciative of any help I recieve. Thanks in advance.
public class TestApplication
{
// hashmap
private HashMap<String, ArrayList <String>> Application = new HashMap<String, ArrayList <String>>();
// hashset
private HashSet<String> loginsIssued = new HashSet<String>();
// An Arry List for storing student information
private ArrayList<String> Student = new ArrayList<String>();
/**
* Constructor for objects of class Application
*/
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);
}
}
/**
* Create a Student Information
*/
public void TestApplication(String personalIdNo, String Surname, String Forename)
{
Student.add(Surname);
Student.add(Forename);
Student.add (personalIdNo);
}
/**
* Add Login
* Pull First Letter of Forenames
* Pull First Letter of Surname
* Generate Random Number
* Print
*/
public void addLogin(String Surname, String Forename)
{
String login = "";
{
System.out.println (Surname.charAt(0) + "" + " " + Forename.charAt(0) + " " + Math.round(Math.random()*999+1));
Student.add(login);
loginsIssued.add(login);
}
}
/**
* CONDITION 1
* Check whether the ID supplied is only numbers
*/
public boolean isNumeric(String personalIdNo)
{
if (personalIdNo.matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {
return true;
}
else
{
return false;
}
}
/**
* CONDITION 2
* Check whether the ID supplied has a length of 10
*/
public boolean checkLength(String personalIdNo)
{
if (String.valueOf(personalIdNo).length()==10)
{
return true;
}
else
{
return false;
}
}
/**
* CONDITION 3
* Check whether the ID supplied starts with 1
*/
public boolean checkFirstDigit(String personalIdNo)
{
if (personalIdNo.startsWith("1"))
{
return true;
}
else
{
return false;
}
}
/**
* Validation Check - Check if it satisfies all conditions.
*/
public boolean isValidpersonalIdNo(String personalIdNo)
{
if (isNumeric(personalIdNo) && checkLength(personalIdNo) && checkFirstDigit(personalIdNo))
{
return true;
}
else
{
return false;
}
}
/**
* FORENAME
* Add Forename
*/
public void addForename(String Forename)
{
Student.add(Forename);
}
/**
* Return Surname
*/
public String getSurname()
{
return Student.get(0);
}
}