Question: A Java question. Write the class Staff . It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor

A Java question. Write the class Staff. It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor takes an ArrayList of String names as a parameter. In addition to the constructor, you need to implement the following methods

The methods

1. public boolean equals(Staff other) - Determines if the other Staff contains all the same elements in the same order as this Staff 2. public boolean sameContents(Staff other) - Determines if the other Staff and this Staff contain exactly the same elements but in any order 3. public void replaceVowelsWith(String text) Replaces each vowel in every ArrayList element with the replacement value text. Assume the vowels are aeiouyAEIOUY 4. public String mostVowels() Gets the staff member whose name has the most vowels. If more than one has that number of vowels, return the first. Return null if the list is empty. Assume the vowels are aeiouAEIOU 5. public String toString() gets a string represent ion using ArrayList's toString method

(set different vowel strings for both of aeiouyAEIOUY and aeiouAEIOU)

---------------------------------------------------------------------------------------------------------------------

Use the following file:

StaffTester.java

import java.util.ArrayList; /** * Tester */ public class StaffTester { public static void main(String[] args) { ArrayList list = new ArrayList<>(); list.add("Goodyear"); list.add("Sathyanantha"); list.add("Keomahavong"); list.add("Addison"); list.add("Smith"); ArrayList list2 = new ArrayList<>(); list2.add("^aeiouy$"); list2.add("^AEIOUY$"); Staff lister = new Staff(list); Staff lister2 = new Staff(list2); Staff empty = new Staff(new ArrayList()); //test an empty list lister.replaceVowelsWith("*"); System.out.println(lister); System.out.println("Expected: [G**d***r, S*th**n*nth*, K**m*h*v*ng, *dd*s*n, Sm*th]"); lister2.replaceVowelsWith("#"); System.out.println(lister2); System.out.println("Expected: [^######$, ^######$]"); empty.replaceVowelsWith("*"); System.out.println(empty); System.out.println("Expected: []"); //testing equals list.clear(); list.add("Goodyear"); list.add("Sathyanantha"); list.add("Keomahavong"); list.add("Addison"); list.add("Smith"); lister = new Staff(list); list2.clear(); list2.add("Goodyear"); list2.add("Sathyanantha"); list2.add("Keomahavong"); list2.add("Addison"); list2.add("Smith"); lister2 = new Staff(list2); System.out.println("equal?: " + lister.equals(lister2)); System.out.println("Expected: true"); list2.remove(list2.size() - 1); System.out.println("equal?: " + lister.equals(lister2)); System.out.println("Expected: false"); System.out.println("contains?: " + lister.sameContents(lister2)); System.out.println("Expected: false"); list2.add(1, "Smith"); System.out.println("contains?: " + lister.sameContents(lister2)); System.out.println("Expected: true"); list2.set(1, "smith"); System.out.println("equal?: " + lister.equals(lister2)); System.out.println("Expected: false"); System.out.println("equal?: " + empty.equals(empty)); System.out.println("Expected: true"); System.out.println(lister.mostVowels()); System.out.println("Expected: Keomahavong"); list.remove(2); System.out.println(lister.mostVowels()); System.out.println("Expected: Goodyear"); System.out.println(empty.mostVowels()); System.out.println("Expected: null"); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!