There are no errors but the driver won't enter the try block at the bottom. "Test" should print to the console, but it doesn't. I.e. the Employees aren't instantiated.
Code:
public Employee(String name, String gender, String DOB, String jobTitle, int salary) throws InvalidDateException{
employeeName = name;
employeeGender = gender;
employeeDOB = DOB;
employeeJobTitle = jobTitle;
employeeSalary = salary;
//Some problem with using this if statement
if(validDOB(DOB)==false){
throw new InvalidDateException("Please enter date in format: DD/MM/YYYY");
}
}
public boolean validDOB(String date){
if(date.matches("[0-9]{2}/[0-2][0-9]/[0-9]{4}")){
return true;
}
return false;
}
Code:
public class Driver {
public static void main(String[] args) {
//Create space in memory and initialise *fields*
//WHY WON'T IT ENTER THE TRY-CATCH??
try {
Employee fred = new Employee("Fred Flinstone", "Male", "02/02/1960", "Manager", 25250);
Employee lisa = new Employee("Lisa Simpson", "Female", "09/05/1981", "Sales Staff", 19750);
Employee charlie = new Employee("Charlie Brown", "Male", "03/11/1950", "Sales Staff", 17500);
System.out.println("test");
} catch(InvalidDateException e) {
e.getMessage();
}
}
}