Keeping with my New Years resolution of trying new things while teaching Maths, I decided to try some Java coding in Maths class this week. I teach Maths to first year Computing students and the past few weeks have been spent brushing up on various topics such as fractions, significant digits, prime factorisation, percentages and sequences and series. These students are also learning their first programming language (Java) at the moment. To give them a sense of the importance of being able to work through calculations, and create test data for their Java programs, I decided to work through a basic payslip calculation as follows:

*John is paid a salary of €45,126 per year. He is paid monthly. PRSI is calculated as 8% of the total salary, pension as 2¼% of the total salary and union subscriptions as ¼% of the total salary. His tax is calculated as 21% of the first €28,000 and 42% of the amount over €28,000.*

*Calculate the amount he pays in PRSI per month**Calculate the amount he pays in pension contributions per month**Calculate the amount of tax he pays per month**Calculate his union subscriptions per month**Calculate his take home pay per month*

So we started by working through the calculations in class. This gave us some test data with which to check that the program worked as it should. Next we started to design our program breaking down the tasks into manageable steps starting with calculating the monthly salary. This allowed us to talk through choosing their variables to hold the data and following good naming conventions when deciding on the variable names. Rather than let the students loose to just write the program themselves (they are after all less than 3 weeks into learning Java), we worked through the program together. We started by calculating the monthly pay and prnting this out. We compiled the program and ran it to make sure we had the correct value using our test data from above.

Next they attempted to code the PRSI calculation after discussing how they might go about it, discussing performance issues around calculating a percentage (for example multiplying by 0.08 rather than multiplying by 8 and dividing by 100). We then worked through the pension and union calculations in a similar fashion. We did these calculations one at a time, compiling and running after each one and checking to make sure that the calculations were correct. Some of the students forgot to convert the percentage from 2.25 to 0.0225 etc so having the test data proved very useful. Finally we tackled the tax calculation and the take home pay again checking that our calculations were correct.

What I wanted them to learn from the process was:

- how you need to work through each step in a calculation in order to be able to create a program to do it
- the importance of test data to confirm that the program works as it should (it’s not enough for the program to compile and run!!)
- how they write their code can have an impact on the performance of the code that they write (many of the students created unnecessary variables and stored intermediate data which was not required)
- the maths that they are doing in my class is not seperate from the Java that they are learning in other classes

I did coding with three different groups this week and I think that it was a huge success. The students seemed to really engage in the process and I hope that they enjoyed it as much as I did and that they learned something in the process. I chose Java because my students are currently learning Java and will need to be able to test the Java code that they write. I think that Scratch could be used with younger students to work through Maths topics in a similar way.