Your first step is to put that all in a method, then call it from the main you already have. When you have that working, then just do the same thing in another class.