Question

1. What does the body of your Pair toString method look like? A. return "LEFT: "...

1. What does the body of your Pair toString method look like?

A. return "LEFT: " + left + " RIGHT: " + right;

B. return System.out.println("LEFT: " + left + " RIGHT: " + right);

C. System.out.println("LEFT: " + left + " RIGHT: " + right);

D. System.out.println("LEFT: " + String + " RIGHT: " + Integer);

2. What does the signature (the first line) of the generic constructor look like in the class?

A. public Pair<U,V>(U u_value, V v_value)

B. public Pair(String U, Integer V)

C. public Pair(U u_value, V v_value)

D. public Pair(U = String, V = Integer)

3. Pick all valid ways to make a new variable of type Pair, with String for both type parameters.

A. Pair<String, String> ss = new Pair(U = "David", V = "J");

B. Pair<String, String> ss = new Pair<>("David", "J");

C. Pair<String, String> ss = new Pair<String, String>("David", "J");

D. Pair<> ss = new Pair<String, String>("David", "J");

4. What method did you use to find the index of "CS1410" in the ArrayList?

A. clear

B. locationOf

C. findValue

D. indexOf

5. Why did the first approach remove and the second approach not remove?

A. In the second case, there was not a named variable holding the reference of the object, so it no longer existed.

B. In the first case, the variable name adding and removing was the same, so it removed. In the second case, there was no variable name, and the name couldn't be compared.

C. Remove works on objects, not on values being the same. In the first case, the reference to the original object was passed in, so it was removed. In the second case, a new object with the same values was passed in, but that is not the same object as in the ArrayList, so it was not removed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:------------

  1. C. System.out.println("LEFT: " + left + " RIGHT: " + right);

  2. A. public Pair<U,V>(U u_value, V v_value)

  3. B. Pair<String, String> ss = new Pair<>("David", "J");

    C. Pair<String, String> ss = new Pair<String, String>("David", "J");

  4. D. indexOf

  5. C. Remove works on objects, not on values being the same. In the first case, the reference to the original object was passed in, so it was removed. In the second case, a new object with the same values was passed in, but that is not the same object as in the ArrayList, so it was not removed.

Add a comment
Know the answer?
Add Answer to:
1. What does the body of your Pair toString method look like? A. return "LEFT: "...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a toString method for the Scores class. It should print the Scores object as follows:...

    Write a toString method for the Scores class. It should print the Scores object as follows: [(EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) , (EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) ,(EntryName, EntryScore), (EntryName, EntryScore), (EntryName, EntryScore) , (EntryName, EntryScore)] GameEntry.java public class GameEntry { protected String name;   // name of the person earning this score protected int score;   // the score value /** Constructor to create a game entry */ public GameEntry(String n, int s) { name = n; score =...

  • Override toString() for the class HighScores. It should return a String that contains all of the...

    Override toString() for the class HighScores. It should return a String that contains all of the high scores in entries, formatted nicely. Note that toString is already implemented for the Score class. Then, write a driver program (in a file named Main.java) that thoroughly tests HighScores (i.e. add and remove scores from the list, add scores to an already full list, make sure the list remains sorted, etc). Score.java public class Score { protected String name; // name of the...

  • import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements...

    import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements Iterable<Pair<K, V>> {    private static final long serialVersionUID = -6229569372944782075L;       public void add(K k, V v) {        if (!containsKey(k)) { put(k, new LinkedList<V>()); } get(k).add(v);    }       public V removeFirst(K k) {               if (!containsKey(k)) { return null;        } V value = get(k).removeFirst(); if (get(k).isEmpty()) { super.remove(k); } return value;    }...

  • //MultiValuedTreeMap.java import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; //import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>>...

    //MultiValuedTreeMap.java import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; //import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements Iterable<Pair<K, V>> {    private static final long serialVersionUID = -6229569372944782075L;       public void add(K k, V v) { // Problem 1 method        // empty linked list, with key=k         if (!containsKey(k)) {               put(k, new LinkedList<V>());         }         // adding v to the linked list associated with key k         get(k).add(v);    }    public V removeFirst(K k)...

  • Comparing the insertion and removing performance between ALPQueue with HeapPQueue. Requirements: 1/ Task1: implement a concrete...

    Comparing the insertion and removing performance between ALPQueue with HeapPQueue. Requirements: 1/ Task1: implement a concrete ALPQueue class (an ArrayList based priority queue) that extends the AbstractPQueue discussed in the class, along with PQueue.java, ArrayList.java, List.java, PQEntry.java , EntryComparitor.java, and OutOfRangeException.java given in the class (any other implementation of above classes that are not compatible with List interface and AbstractPQueue class will not receive any credit). 2/ Task2: implement a concrete HeapPQueue class (a Heap based priority queue) that extends...

  • Array lists are objects that, like arrays, provide you the ability to store items sequentially and...

    Array lists are objects that, like arrays, provide you the ability to store items sequentially and recall items by index. Working with array lists involves invoking ArrayList methods, so we will need to develop some basic skills. Let's start with the code below: The main method imports java.utii.ArrayList and creates an ArrayList that can hold strings by using the new command along with the ArrayList default constructor. It also prints out the ArrayList and, when it does, we see that...

  • Problem 2 Using the Album and Music StoreDemo from problem 1, write a method to find...

    Problem 2 Using the Album and Music StoreDemo from problem 1, write a method to find all of the albums that are cheaper than a specific price In the MusicStoreDemo, add a new method called getAlbumsCheaperThan. The method passes in the ArrayList of albums and the price. The method will return an ArrayList of all albums cheaper than the price passed in. Update the main method in the Music Store Demo and have it find all of the albums that...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • Hi All, Can someone please help me correct the selection sort method in my program. the...

    Hi All, Can someone please help me correct the selection sort method in my program. the output for the first and last sorted integers are wrong compared with the bubble and merge sort. and for the radix i have no idea. See program below import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Sort { static ArrayList<Integer> Data1 = new ArrayList<Integer>(); static ArrayList<Integer> Data2 = new ArrayList<Integer>(); static ArrayList<Integer> Data3 = new ArrayList<Integer>(); static ArrayList<Integer> Data4 = new ArrayList<Integer>(); static int...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT