Need help in java. I have provided my starter code but do notknow how to conduct the next steps. Please explain as well. In theGeneric math<T> class, create a new method named printAddwhich needs to accept the parameter of type T. Add this value tothe existing number stored in the value field and print theresult.
Please not, it does not need to update the stored value, justprint the result and it is okay to treat numbers as floating-pointvalues and finally it does not need to provide a class thatinstantiates an instant of GenericMath<T> , just theclass.
CODE:
public class GenericMath <T extends Number>{
private T value;
public GenericMath(T value) {
this.value = value;
}
public T getValue () {
return this.value;
}
public void setValue (T value) {
this.value = value;
}
public void printValue() {
System.out.println(this.value);
}
}
---------------------------------------------------------------------------------------------------------------------------------------------
public class Main {
public static void main(String[] args) {
// Store value 5.0
var generic = new GenericMath<Double>(5.0);
//Set new value
generic.setValue(3.0);
//Print Value
generic.printValue();
}
}
Need help in java. I have provided my starter code but do not know how to conduct the next steps. Please explain as well
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am