Arrays Lab Create a class called CustomerListerArray with a main method that dec
ID: 3726756 • Letter: A
Question
Arrays Lab Create a class called CustomerListerArray with a main method that declares and instantiates an array of Stringobjects called customerName. The array should have room for seven String objects. Assign each of the following Strings to sequential locations in the array 1 beginning at array index 0. Do not use an array initializer list to create the customerName array 0 Beth Jerry 2Rick 3 Summer 4Morty Write a for each loop to print the array of names to the console. Each name MUST be on a separate line. (After printing the contents of the array, print a blank new line for formatting) In the comments text box in the Blackboard assignment link answer the following questions: 1. What is displayed for the last two array elements? 2. Why is it that value? Move the existing elements from indexes 3 and 4 so that you can add the Strings "Jerry" and "Jessica" into index 3, and 4, respectively, and the array contains the following elements in this order: 0 Beth 0 Beth 1 Je 2 Rick Jerry 2 Rick 3 Je 4 Jessica 5 Summer 4 5 Summer 6 Morty 6 Morty Write another for each loop to print the array of names to the console. Again, each name MUST be on a separate line. (After printing the contents of the array, print a blank new line for formatting) Write a second, traditional for loop that checks each element for the String "Jerry", if found in the array, remove it, shift the remaining elements up, and print the array of names to the console in the same manner as the rest of the lab. In the comments text box for your Blackboard submission, answer the question: Are both instances of "Jerry" removed correctly from the array? Why or why not? In other words, explain what you observe in your code. 3. 4. 2 Upload your file CustomerListerArray.java to the assignment link in Blackboard.
Explanation / Answer
Here You Go !!!!
class CustomerListerArray{
public static void main(String[] args){
String[] customerName = new String[7];
customerName[0] = new String("Beth");
customerName[1] = new String("Jerry");
customerName[2] = new String("Rick");
customerName[3] = new String("Summer");
customerName[4] = new String("Morty");
for(String i:customerName){
System.out.println(i); // last two will show null because there hasnt been any entry made
} // null means that it is not pointing to any string
System.out.println("");
customerName[5] = customerName[3];
customerName[6] = customerName[4];
customerName[3] = new String("Jerry");
customerName[4] = new String("Jessica");
for(String i:customerName){
System.out.println(i);
}
System.out.println("");
for(int i = 0;i<7;i++){
if(customerName[i].compareTo("Jerry")==0){
for(int j= i;j<6;j++){
customerName[j] =customerName [j+1];
customerName[j+1]="";
}
// both instances of jerry are removed from the array
}
}
for(String i:customerName){
System.out.println(i);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.