Question
A Java problem. Write the class Staff . It contains methods that manipulate an ArrayList of Strings representing the names of staff members. The constructor
A Java problem. 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
---------------------------------------------------------------------------------------------------------------------
Use the following file:
StaffTester.java
import java.util.ArrayList; /** * Tester */ public class StaffTester { public static void main(String[] args) { ArrayListlist = 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
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