How to make an array that increases if the user wishes?

0

I have a problem in a programming project. The program asks for the following:

  • This is a Question Database (for example, an ENEM, or Vestibular).

  • I need to do some commands like add students, teachers, tell who you are, and if you do not 'add' it, but that part is already done. I made ArrayList, for both (any suggestions? I'm open to anything!)

  • I need to add questions if you are a teacher. I made a teacher variable, which is boolean , and can "register" in the program as one, or with a student. However, how do I array increase in size when the teacher adds new questions? I've done array of two dimensions, because I need to add questions for each year (Philosophy [QUESTION] [YEAR], Philosophy [3] [0], Philosophy [3] [1], Philosophy [3] [2] , different issues, from different years!) . Also, as far as the answers to each question are concerned, I made another array that has the same size as the questions, which corresponds to it, for example, an array of Sociology, with X questions for the 3 years, I I made another, of answers, with the X questions, with each answer separated each with a '|', for each year.

Any suggestions? package final

package projetofinal;

public class provaQuestoes {
    String[][] Biology = new String[0][3];
    String[][] BiologyAnswer = new String[0][3];
    //Claro que, para cada matéria, mas esse é só um exemplo

    String questionBiology(int year, int question){
        return Biology [year][question];
    }//Cada matéria tem um método que faz isso

    void chooseSubject(int y, int subject, int question){
        switch(subject){
            case 1:
                questionBiology(question, y);
                break;
               // Cada matéria tem um valor que corresponde a um método que envia uma pergunta,
               // porquê eu preciso também que eu crie um teste para o aluno,
               // mas isso é para depois

    [..]
    void addQuestion(int subject, String question, String answers,int y){
        switch(subject){
            case 1:
        \insira o código aqui
            break;

This is a class that has all the subjects of each year. The main is another class, where I made a "decorated" menu, all in text, with a case, which allows user registration (student / teacher), entry as one of these two, with name registration, question record and other things.

    
asked by anonymous 09.11.2014 / 15:08

1 answer

1

I think you have to use Array in cases where you have a defined size, which will never change ... If you think the data will increase, do not use array, use other data structures, such as ArrayList.

If you have already seen object orientation see:

Instead of creating array for each Subject, do the following:

  • Creates a Materia class with attributes (id,nome) ;
  • Creates a class Questao with attributes (id,materia,ano,questao,resposta)
  • So you will have to fill in the object Questao and add it in the ArrayList.

        
    09.11.2014 / 18:00