I am still pretty new to programming and need a little help with a program I am writing. It consists of two classes, a generic OrderedPair class and an ObjectPairTest class. This so far is my OrderedPair class: I used some of the suggestions from the comments below and have changed my ObjectPair class to as follows:
package lab2;
public class OrderedPair<F, S>{
public F getFirst;
public S getSecond;
private F first;
private S second;
public OrderedPair(F first, S second ){
this.first = first;
this.second = second;
}
public F getFirst() { return first; }
public S getSecond() {return second;}
public String toString() {return first.toString() + " | "+second.toString();}
public static final OrderedPair<String, Integer> c1 = new OrderedPair<String, Integer>("Pi", 3);
public static final OrderedPair<String,String> c2 = new OrderedPair<String, String>("Great", "Super");
public static final OrderedPair<Integer, Integer> c3 = new OrderedPair<Integer, Integer>(1, 2);
public static final OrderedPair<Float, String> c4 = new OrderedPair<Float, String>( 5f, "Maximum");
public static final OrderedPair<Integer, Float> c5 = new OrderedPair<Integer, Float>(69, 69f);
}
And my ObjectPairTest class is as follows:
package lab2;
public class OrderedPairTest{
public static void main(String[] args){
System.out.println(c1.toString());
System.out.println(c2.toString());
System.out.println(c3.toString());
System.out.println(c4.toString());
System.out.println(c5.toString());
}//End class Main
}//End class OrderedPairTest
However when I try and run, it gives me the error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
c1 cannot be resolved
c2 cannot be resolved
c3 cannot be resolved
c4 cannot be resolved
c5 cannot be resolved
at lab2.OrderedPairTest.main(OrderedPairTest.java:6)
Thank you all for your help so far.