Home / Expert Answers / Computer Science / this-is-the-method-which-should-be-implemented-public-class-registerapp-public-static-string-exe-pa731

(Solved): this is the method which should be implemented: public class RegisterApp { public static String exe ...



this is the method which should be implemented:

public class RegisterApp { public static String execute(Name nm, Register regst) {

return "";
}
}

 

In the src \( > \) main package, you will notice a class called RegisterApp that has a method called execute, which accepts a

 

 

 

so far I got this but won't pass my tests:

public static String execute(Name nm, Register regst) \{
// Remove a name at index 1 from the register
regst.remove(1);
// Adthese are the tests:

???????@Test
    public void testExecute() {
        Register r = new Register(10);
        r.addName(new Name("Joe", "Bloggs"));
        r.addName(new Name("Fred", "Jones"));
        r.addName(new Name("Nila", "Singh"));        
        
        String result = RegisterApp.execute(new Name("Cassie", "Downturn"), r);
        
        String expectedResult = "j.blo@email.com\nn.sin@email.com\nc.dow@email.com\n";
        
        assertEquals("The string returned should match the expected result (run 1)", expectedResult, result);
        
        
        /* Test with a second set of input data */
        Register r2 = new Register(10);
        r2.addName(new Name("Tim", "Russ"));
        r2.addName(new Name("David", "Blunt"));
        r2.addName(new Name("Remi", "Patel"));        
        
        String result2 = RegisterApp.execute(new Name("Cassie", "Downturn"), r2);
        
        String expectedResult2 = "r.pat@email.com\nc.dow@email.com\n";
        
        assertEquals("The string returned should match the expected result (run 2)", expectedResult2, result2);    
    }
    
}

 

 

 

??????????????

In the src \( > \) main package, you will notice a class called RegisterApp that has a method called execute, which accepts a Name and a Register object and returns a String. Currently, it simply returns an empty string. It should however do the following: - Remove a name at index 1 from the Register regst. - Add the Name nm (passed as a parameter to the execute method) to the register. - Return a String that represents each name in the register that has a first name containing either of the characters \( a \) or \( e \) in the format: "initial.surnamefirst3letters@email.com", (e.g. Fred Jones would be "f.jon@email.com"), each followed by a new line. Each resultant email address should therefore be in lowercase and only the first three letters of the surname should be included. public static String execute(Name nm, Register regst) \{ // Remove a name at index 1 from the register regst.remove(1); // Add the Name nm to the register regst.add \( (\mathrm{nm}) \); // Create a StringBuilder to store the result StringBuilder result \( = \) new StringBuilder(); // Iterate over the names in the register for (Name name : regst) \{ // Get the first name and surname of the current name String firstName \( = \) name.getFirstName(); String surname \( = \) name.getSurname(); // Check if the first name contains either 'a' or 'e' if (firstName.contains("a") || firstName.contains("e")) \{ // If it does, append the email address in the correct format to the result result.append(firstName.toLowerCase() + "." + surname.substring(0, 3).toLowerCase() + "@company.com\n"); \} \}


We have an Answer from Expert

View Expert Answer

Expert Answer


Here is the complete implementation of the execute method based on the requirements you provided:- public static String execute(Name nm, Register regs
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe