How to develop a java code Like above img ?