Design a class name Tuple to represent tuples of form key va

Design a class name Tuple to represent tuples of form (key, value), where key is of type int and value is of type double. This class will have following constructor and public methods Tuple (int keyP, float valueP) Creates Tuple object with keyP as key and valueP as value. getKey () Returns key getValue () Returns value equals (Tuple t) returns true if this tuple equals t; otherwise returns false.

Solution

Tuple.java


public class Tuple {
   private int key;
   private float value;
   public Tuple(int keyP, float valueP){
       key = keyP;
       value = valueP;
   }
   public int getKey() {
       return key;
   }
   public void setKey(int key) {
       this.key = key;
   }
   public float getValue() {
       return value;
   }
   public void setValue(float value) {
       this.value = value;
   }
   public boolean equals(Tuple t){
       if(t.getKey() == getKey() && t.getValue() == getValue()){
           return true;
       }
       return false;
   }
}

 Design a class name Tuple to represent tuples of form (key, value), where key is of type int and value is of type double. This class will have following constr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site