DEV Community

Judy
Judy

Posted on

Add a compute column to a csv file #eg40

The csv file below stores assessment parameters:

Image description
Use Java to do this: Compute Final Grade (the 4th column) value according to the existing 3 columns using the formula Lab Exercise * 30% + Long Quiz * 30% + Alternative Assessment * 40%, and write the result to a new csv file.

Image description
Write the following SPL code:

Image description
T()function parses a csv file or generates a new one. derive() function adds a compute column.

Read How to [Call a SPL Script in Java](T()function parses a csv file or generates a new one. derive() function adds a compute column.

Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.) to find how to integrate SPL into a Java application.

This is one of the problems on StackOverflow. You can click on it to see that the conventional solution is quite complicated, but the SPL approach is really simple and efficient.

SPL open source address

Top comments (0)