Question: I need help with this: 1. Use the arraycopy method in the System class to make a copy of the familyNames array. 2. Compare to
I need help with this:
1. Use the arraycopy method in the System class to make a copy of the familyNames array.
2. Compare to see if the copy and the original are equal.
3. Sort the first familyNames array.
4. Again compare to see if the 2 arrays are equal.
5. Use the binarySearch method to search for the same name in both arrays.
-Because the search is case sensitive make sure to upper case or lower case the family names in the array.
-Hint: Easiest to upper or lower case as you are capturing the family names from the keyboard into the array.
-Example: familyNames[i] = input.nextLine().toLowerCase() OR input.nextLine().toUpperCase()
-Also make sure to upper or lower case the family name you are searching for.
-In a separate method that receives the 2 arrays, use the enhanced for loop to print their content.
SAMPLE OUTPUT:
How many family members in your immediate family including yourself? 3 Enter a family member's name: Brad Enter a family member's name: Estelle Enter a family member's name: Brandon
The familyNames array equals the familyNamesCopy array.
The familyNames array has been sorted. The familyNames array doesn't equal the familyNamesCopy array.
Which family name are you looking for? Brandon Found brandon at element 1 in the familyNames array. familyNames Array: brad brandon estelle familyNamesCopy Array: brad estelle brandon
This is what I have so far:
import java.util.Scanner;
public class TemidaraAgbesanwaLE61 {
private static Scanner input = new Scanner(System.in); public static void main(String[] args) {
int size = arraySize();
String names[] = new String[size];
int age[] = new int[size];
for (int i = 0; i < size; i++) { input.nextLine(); System.out.printf("%nEnter the family memeber's name :"); names[i] = input.nextLine(); System.out.printf("%nEnter this family member's age : "); age[i] = input.nextInt(); }
display(names, age);
}
private static void display(String[] names, int[] age) { System.out.printf("%n%nMy Family%n"); for (int i = 0; i < names.length; i++) { System.out.printf("%n%nName: " + names[i]); System.out.printf("%nAge:" + age[i]);
} }
public static int arraySize() { int size; System.out.printf("%nHow many family members in your immediate family including yourself?"); size = input.nextInt(); return size; }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
