In: Computer Science
Suppose that you have the following vector objects:
studentLastName = ["Smith", "Shue", "Cox", "Jordan"]
studentFirstName = ["James", "Sherly", "Chris", "Eliot"]
a. Write a Java statement that outputs the first name of the third student
b. Write a Java statement that outputs the last name of the second student
c. Write a Java statement that outputs the first name followed by the last name separated by a single blank space of the first student
d. Write the necessary Java statements so that the first name and last name of Eliot Jordan are interchanged.
e. Write a Java statement that changes the names James Smith and Sherly Shue to Sherly Smith and James Shue
By changing the vector object studentLastName
By changing the vector studentFirstName
f. Write a for loop that prints all the students" names.
Below are the required Java statements:
// a. first
name of the third student
System.out.println(studentFirstName.get(2));
// b. last
name of second student
System.out.println(studentLastName.get(1));
// c. first
name, last name of first student
System.out.println(studentFirstName.get(0) + " " +
studentLastName.get(0));
// d.
interchange first name and last name of Eliot Jordan
String temp =
studentFirstName.get(3);
studentFirstName.set(3,
studentLastName.get(3));
studentLastName.set(3,
temp);
// e. change
the names James Smith and Sherly Shue to Sherly Smith and James
Shue
String temp2 =
studentFirstName.get(0);
studentFirstName.set(0,
studentFirstName.get(1));
studentFirstName.set(1,
temp2);
// f. print
all student names
for (int i = 0; i <
studentFirstName.size(); i++) {
System.out.println(studentFirstName.get(i) + " " +
studentLastName.get(i));
}
Below is the output:
This completes the requirement. Let me know if you have any questions.
Thanks!