#6 done in java