I have figured out how to serialize multiple objects, however I am utterly convinced I can use some kind of loop for the if statements below, to avoid duplication. Please can someone advise how I would do this?
I have 20 objects in total, this code snippet shows the "if statements" for 4 of them.
import java.util.InputMismatchException;
import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
public class Serializer extends WriteClub
{
public void Serialize()
{
MainMenu pass_choice = new MainMenu();
int passed_choice = pass_choice.chooseTeam();
if(passed_choice==1){
ClubInfo club = new ClubInfo("Arsneal" , "Emirates" , "Premier League" , 11122333 , 60000);
tryWriteClub(club);
} // end if 1
if(passed_choice==2){
ClubInfo club1 = new ClubInfo("Aston Villa" , "Villa Park" , "Premier League" , 111223334 , 40000);
tryWriteClub(club1);
} // end if 2
if(passed_choice==3){
ClubInfo club2 = new ClubInfo("Bournemouth" , "Dean Court" , "Premier League" , 111223335 , 20000);
tryWriteClub(club2);
} // end if 3
if(passed_choice==4){
ClubInfo club3 = new ClubInfo("Chelsea" , "Stamford Bridge" , "Premier League" , 111223336 , 50000);
tryWriteClub(club3);
} // end if 2
}
}