Question
this is the method which should be implemented: public class RegisterApp { public static String execute(Name nm, Register regst) { return ; } } so
this is the method which should be implemented:
public class RegisterApp { public static String execute(Name nm, Register regst) {
return ""; } }
so far I got this but won't pass my tests:
these 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 n.sin@email.com c.dow@email.com "; 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 c.dow@email.com "; 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 (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 "); \} \}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started