40.6k views
0 votes
Build a set of parallel vectors of integers that are designed to manage your scores on your labs. One vector holds the score you earned. The second vector holds the maximum possible score. Write the code to populate them with your scores 10/10, 8/10 and 9/10.

1 Answer

3 votes

Answer:

  1. import java.util.Vector;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Vector<Integer> score = new Vector<>();
  5. Vector<Integer> maxScore = new Vector<>();
  6. score.add(10);
  7. score.add(8);
  8. score.add(9);
  9. maxScore.add(10);
  10. maxScore.add(10);
  11. maxScore.add(10);
  12. System.out.println(score.get(1));
  13. System.out.println(maxScore.get(1));
  14. }
  15. }

Step-by-step explanation:

The solution is written in Java.

Since we are going to create Vector, we have to import Vector class into our program (Line 1).

Next, declare two parallel Vector in integer type (Line 6-7). Score vector is to keep the score earned by user and maxScore is to store maximum possible score.

Next, we can populate our two vectors using add method (Line 9 - 15).

We can extract the values stored in the vectors using get method. This get method will accept one index to retrieve the corresponding value from vectors. The Line 17-18 will print out 8 and 10.

User Asbestossupply
by
4.0k points