Need help in java. I have provided my starter code but do not know how to conduct the next steps. Please explain as well

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Need help in java. I have provided my starter code but do not know how to conduct the next steps. Please explain as well

Post by answerhappygod »

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();
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply