Lets say I have a class below with getters and setters but with only default constructor.
Note: I'm not allowed to change the structure of this class.
class Target {
private String year;
private String month;
private String name;
private double target;
private double achieved;
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getTarget() {
return target;
}
public void setTarget(double target) {
this.target = target;
}
public double getAchieved() {
return achieved;
}
public void setAchieved(double achieved) {
this.achieved = achieved;
}
}
I have to add the Target and Achieved columns values based on year and Name.
Year Month Name Target Achieved
2018 8 Joey 50.00 10.00
2018 9 Joey 200.00 100.00
2018 9 Fred 200.00 150.00
2018 9 Fred 20.00 50.00
So the output would be:
Year Month Name Target Achieved
2018 8 Joey 50.00 10.00
2018 9 Joey 200.00 100.00
2018 9 Fred 220.00 200.00
I've seen an example on how I could achieve something like this if I had a constructor that accepts parameters but I'm not so clear on the concept Group by and sum objects like in SQL with Java lambdas?:
How do I achieve this with just the default constructor to get same type List<Target>
but with calculated values of multiple columns?