-1

I will keep it simple and easy for you guys to help me out , this is the example testfile i want to "populate" with data in this way:

1,Justinianos,Maia,2
2,Hulks,Famalicao,5
3,Padres Matias,Porto,12
4,Fanadinhos,Lisboa,4
5,Melancolitos,Vila Nova de Gaia,6
6,Ao Colinho,Sao Romao,7
7,Cavalos do Zodiaco,Cabecas de bastos,10
8,Unicorns,Aveiro,2
9,Rainbows,Coimbra,3
10,One Piece 4 ever,Folgosa,15

id,nomequadra,localidade,qtdcavalos

int,String,String,int

Then this is the class that stores the data:

/**
 * Created by Ricar on 02/04/2017.
 */
public class Quadras {
    private int id;
    private String nomequadra;
    private String localidade;
    private int qtdcavalos;

    public Quadras(){
        id=0;
        nomequadra=null;
        localidade=null;
        qtdcavalos=0;
    }
    public Quadras(int id , String nomequadra, String localidade, int qtdcavalos){
        this.id = id;
        this.nomequadra = nomequadra;
        this.localidade = localidade;
        this.qtdcavalos = qtdcavalos;
    }

    public int getId() {return id;}

    public void setId(int id) {this.id = id;}

    public String getNomequadra() {return nomequadra;}

    public void setNomequadra(String nomequadra) {this.nomequadra = nomequadra;}

    public String getLocalidade() {return localidade;}

    public void setLocalidade(String localidade) {this.localidade = localidade;}

    public int getQtdcavalos() {return qtdcavalos;}

    public void setQtdcavalos(int qtdcavalos) {this.qtdcavalos = qtdcavalos;}
}

This other class joins together all the classes into arraylist for working with the data:

    public class Championship {

    private ArrayList<Quadras> quadras;
    private ArrayList<Participante> participantes;
    private ArrayList<Jornada> jornadas;

    public Championship(){
        this.quadras = new ArrayList<Quadras>();
        this.jornadas = new ArrayList<Jornada>();
        this.participantes = new ArrayList<Participante>();
    }
    public Championship(ArrayList<Quadras> quadras, ArrayList<Participante> participantes, ArrayList<Jornada> jornadas)
    {
        this.quadras = quadras;
        this.participantes = participantes;
        this.jornadas = jornadas;
    }

    public void addQuadras (Quadras s ) {quadras.add(s);}

    public void printQuadras(){

        System.out.println("--------Quadras-------");
        for(int i = 0; i< quadras.size();i++){
            System.out.println(quadras.get(i));
        }
    }

    public void addParticipantes (Participante s ) {participantes.add(s);}
    public void addJornada (Jornada s ) {jornadas.add(s);}
}

I want to populate the Championship Arraylist ,using split on the "," and then convert each substring that has difrent data then string like Integer.

After that i want to be able to reverse the process also, because i will be inserting data manualy into the txt file, but i want to be able to load from the file and store in the file.

I already have a createnewFile(); method and deleteFile(); method.

If someone could five me a hand here i would be very happy :)

Thx for spending thime reading my problem!

  • Use openCSV http://opencsv.sourceforge.net/ – iavanish Apr 04 '17 at 09:03
  • And what is your question? You dumped some requirements; and some code. Now what? This is not a free "code writing service". We don't do the rest of your homework for you. If something is not working in that code, that ask a specific question about that. But "me needs help" is not a valid question in this community! – GhostCat Apr 04 '17 at 11:24

1 Answers1

0

You can check if is a digit or a number using the code in this link:

What is the best way to tell if a character is a letter or number in Java without using regexes?

After, you can populate your objects.

Hope it helps

Community
  • 1
  • 1
FFdeveloper
  • 241
  • 3
  • 14