Question

In: Computer Science

Suppose that you have the following vector objects: studentLastName = ["Smith", "Shue", "Cox", "Jordan"] studentFirstName =...

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.

Solutions

Expert Solution

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!


Related Solutions

Suppose that you visit the nursery at Cox South and discover that it contains 21 babies....
Suppose that you visit the nursery at Cox South and discover that it contains 21 babies. If none of them are identical siblings, then what is the probability that these 21 babies consist of 11 boys and 10 girls? *Show complete solution using binomial distribution. Explain every part of the solution.
Rewrite the Jars problem to use a Jar class and a vector of Jar objects The...
Rewrite the Jars problem to use a Jar class and a vector of Jar objects The Jar class has 2 private members - volume, capacity, a default constructor, a 1 parameter constructor, 2 accessors but only 1 mutator, two boolean methods isEmpty and IsFull, a 1 Jar reference parameter method, pour, that pours the contents of its parameter into the method's Jar jar.h #include <algorithm> #include <vector> using namespace std; class Jar { public: Jar(int new_capacity =8); bool isEmpty(); bool...
Rewrite the Jars problem to use a Jar class and a vector of Jar objects The...
Rewrite the Jars problem to use a Jar class and a vector of Jar objects The Jar class has 2 private members - volume, capacity, a default constructor, a 1 parameter constructor, 2 accessors but only 1 mutator, two boolean methods isEmpty and IsFull, a 1 Jar reference parameter method, pour, that pours the contents of its parameter into the method's Jar. /* A man goes to a bathtub with two jars, of which one holds exactly 3 pints and...
Rewrite the Jars problem to use a Jar class and a vector of Jar objects The...
Rewrite the Jars problem to use a Jar class and a vector of Jar objects The Jar class has 2 private members - volume, capacity, a default constructor, a 1 parameter constructor, 2 accessors but only 1 mutator, two boolean methods isEmpty and IsFull, a 1 Jar reference parameter method, pour, that pours the contents of its parameter into the method's Jar. /* A man goes to a bathtub with two jars, of which one holds exactly 3 pints and...
Suppose there are only two countries in the world Jordan and Lebanon with equal population. Jordan...
Suppose there are only two countries in the world Jordan and Lebanon with equal population. Jordan can produce by all of its resources 50 units of wheat, while Lebanon can produce by all of its resources 80 units of wheat. Jordan can produce by all of its resources 25 units of cloths, while Lebanon can produce by all of its resources 30 units of cloths. (a) Which country has the absolute advantage in wheat and which country has the absolute...
Suppose you have three, user input temperatures (double) assigned to three objects (chem1, chem2, and chem3)....
Suppose you have three, user input temperatures (double) assigned to three objects (chem1, chem2, and chem3). How would you go about finding which of the three values entered by the user is closest to the value 240.00 WITHOUT THE USE OF LOOPS OR ARRAYS? Solve using Java Programming Language.
Suppose that ? and ? are subspaces of a vector space ? with ? = ?...
Suppose that ? and ? are subspaces of a vector space ? with ? = ? ⊕ ?. Suppose also that ??, … , ?? is a basis of ? amd ??, … , ?? is a basis of ?. Prove ??, … , ??, ??, … , ?? is a basis of V.
Write a code block to perform nested-for-loop sorting on a vector of State objects, arranging by...
Write a code block to perform nested-for-loop sorting on a vector of State objects, arranging by their string name attribute in alphabetical order A-Z. Assume all names are fully uppercase and that there's an assignment operator for the class. The name of the vector is "states".
Suppose you are navigating a spacecraft far from other objects. The mass of the spacecraft is...
Suppose you are navigating a spacecraft far from other objects. The mass of the spacecraft is 3.6 × 104 kg (about 36 tons). The rocket engines are shut off, and you're coasting along with a constant velocity of <0, 31, 0> km/s. As you pass the location <6, 6, 0> km you briefly fire side thruster rockets, so that your spacecraft experiences a net force of <6 × 105, 0, 0> N for 21.0 s. The ejected gases have a...
Suppose the first vector pointed to the right of the page, and the second vector pointed...
Suppose the first vector pointed to the right of the page, and the second vector pointed up toward the top of the page. Which direction would the cross product of these two vectors point?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT