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

Asked

Viewed 123 times

0

I’m having a problem with a programming project.
The program calls for the following:

  • It is a Database of Questions (For example, a ENEM, or Vestibular).

  • I PRECISE make some commands ,like add students, teachers, say who you are, and if you 'don’t exist', add it, but that part is already completed. I did 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" into the program as one, or with a student. However, as I do array that increases in size when the teacher adds new questions? I’ve done two-dimensional array as I need to add questions for each year (Philosophy[QUESTION][YEAR],Philosophy[3][0],Philosophy[3][1],Philosophy[3][2],different questions of different years!). And also, when it comes to the answers to each question, I made another array that is the same size as the questions, which corresponds to it, for example, an array of sociology, with X questions for the 3 years, I made another, of answers, with the X questions, with each separate answer each with a '|', for each year.

Any suggestions? package design;

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 disciplines of each year. The Main is another class, where I made a menu "decorated", 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.

  • 5

    It’s nice to format the question: http://answall.com/editing-help And putting your code is important.

  • In case you are not using a database even right? Mysql for example?

  • No, the 'database' would be the same array, since I don’t know how to program in it

  • Hmmm, got it. It would be nice if you could post your code, you’re very confused to understand.

  • I’ll post it then

  • 1

    Fine, put it there that afternoon when I give a while I reply.

  • 2

    You are worsening formatting, please do not undo other users' improvements. Check out the editing history to see how is the default of the site shown by the 1st editor. The following post is also worth a read: Oh, no! They edited my question!, and formatting help: http://answall.com/editing-help . Thank you.

  • 2

    You can see that the code is all sloppy up there, right? And it’s impossible to fix because you put HTML in the middle of the code. As I said before, the formatting here is in Markdown.

  • 1

    @user3718717 In order to help you and for the question to be readable to future users with the same problem, try to leave the text and codes well formatted. Preferably, use the Text Editor icons to create list, bold, and code indentation effects - avoid HTML tags. Reread your post also after you finish writing it (imagine how you were your mother reading the text). He’s confused.

Show 4 more comments

1 answer

1

I think you have to use Array in cases where you have a set 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’ve seen object orientation see:

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

  1. Creates a class Materia with attributes (id,nome);
  2. Creates a class Questao with attributes (id,materia,ano,questao,resposta)

So you have to fill in the object Questao and add to Arraylist.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.