I have this bugging problem I cannot figure out. I have this exercise:
Complete the following generic Pair class, so that execution of the program gives the indicated output. Do not change main.
class Pair ... { ... }
class GenericPairTest {
public static void main(String[] args) {
Pair<String,Integer> phoneNumber = new Pair<>("Bill's number", 1324);
System.out.println(phoneNumber);
Pair<Double,Double> point = new Pair<>(3.14, 2.32);
System.out.println(point);
}
}
The output is suposed to be like that:
Bill's number 1324
3.14 2.32`
I tried doing this:
import java.util.*;
class Pair <T,U> {
ArrayList<T,U> newList = new ArrayList<>();
Pair(T inT, U inU){
newList.add(inT,inU);
}
}
class GenericPairTest {
public static void main(String[] args) {
Pair<String,Integer> phoneNumber =
new Pair<>("Bill's number", 1324);
System.out.println(phoneNumber);
Pair<Double,Double> point =
new Pair<>(3.14, 2.32);
System.out.println(point);
}
}
But it doesn't work :(