Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Employee{ private String dob; // mm/dd/yyyy private String name; pr

ID: 3612886 • Letter: P

Question

public class Employee{

   private String dob; //  mm/dd/yyyy

    private String name;

    private String boss; // null if noboss? or empty?

   //------------------------------------------------------

    public Employee(String dob, String name,String boss){

        this.dob = dob;this.name = name; this.boss = boss;

    }

    int    getAge() {

       System.out.println("getAge is just a stub"); return -99;

    }

    String getName(){

        return name;

    }

    String getBoss(){

        return boss;

    }

    String getDob(){

        return dob;

    }

              ProtectEmployee

Improve the constructor for Employee. It should discard anyleading or trailing whitespace in the strings that are passed to itand

<!--[if!supportLists]-->·        <!--[endif]-->Check the names passed to it: they must consistof just letters and spaces. The Employee name must contain at leastone letter, but the boss can be a string with no letters. We won'tworry about capitalization for now.

<!--[if!supportLists]-->·        <!--[endif]-->Check the dob passed to it: it must be in theformat /mm/dd/yyyy where mm is in 01..12 (Jan to Dec),dd must be a day consistent with mm (allow Feb 29) and yyyy must bein 1900 .. now

If a name is bad throw a BadEmployeeException which tells whichname was bad and what the given "name" was. If the names are ok butthe dob is bad, throw a BadEmployeeException whose message says itwas a bad dob and tells what the offending dob was.

(Otherwise, it constructs the Employee. For now, don't try to"fix" the names or dob.

Test your improved Employee class by putting test cases intoTester, and running it to verify that the desired behavior occurs(including the messages on the Exceptions). Just add more and moretestcases to Tester -- each time it runs let it run all the tests.This way if your debugging screws up an old test case you will beable to see that you still have a problem.

Explanation / Answer

I'll start you off with checking the name. public Employee(String dob, String name,String boss) {    // remove leading and trailingwhitespace    name =name.trim();    // check if name has characters besides letters &whitespace    // iterate through characters in stringname    // iterate through characters in stringname    for(char c :name.toCharArray())    {
      // if cis not a letter and not a space, throw anexception       if(!Character.isLetter(c)&& c != ' ')       {          throw(newBadEmployeeException("Bad name: "+name));       }    } }