Error when adding side-by-side objects in an array

Asked

Viewed 127 times

1

I need to add the methods get for a ArrayList, I tried with commas to separate, but it doesn’t work, I can only add if one is under the other, which is not good for me. I tried to create the ArrayList of the kind of class I want to pull, but he calls the builders, which also would not serve.

The mistake is:

(current and formal Arguments lists differ in length)

Along with this above lists all means to add items in the list with the same error.

To ArrayList need to store class objects CaixaLapis who basically are gets and sets.

package prj_interdisciplinar;

//importar listas no Java
import java.util.ArrayList;


public class Pedido implements Manipulacao{
    private Data data = new Data(1, 1, 2001);
    private Cliente cliente = new Cliente("semnome", "semcpf", "semtel");
    private float totalpedido;
    private ArrayList cxlapis = new ArrayList();
    private ArrayList papel = new ArrayList();
    private ArrayList caderno = new ArrayList();

    //construtor sem parametros
    public Pedido(){

    }

    //Teste com ArrayList fora do método cadastro
    public void adicionaCaixaLapis(){
        CaixaLapis cxl = new CaixaLapis();
        cxlapis.add(cxl.getQuantidade(), cxl.isColorido(), cxl.getMarca(), cxl.getValor());
    }

    void imprimeLista() {
        for(int i = 0; i<cxlapis.size(); i++){
            System.out.println(cxlapis.get(i));
        }
    }

    /**
     * @return the totalpedido
     */
    public float getTotalpedido() {
        return totalpedido;
    }

    /**
     * @param totalpedido the totalpedido to set
     */
    public void setTotalpedido(float totalpedido) {
        this.totalpedido = totalpedido;
    }

    //calcular pedido
    public void calculaTotalPedido(){
        totalpedido = 0;
    }

    //chamada manipulacao
    @Override
    public boolean cadastro(){
        imprimeLista();
        return true;
    }
    @Override
    public String consulta(){

        return  "texto";
    }
}
  • Instead of add, would not be addAll?

  • I tried with addAll, but the error informs that none of the add methods works because they differ in size, something like, I will try to play the error there in the post.

  • In this case, do those functions return different values? That is, getQuantidade(), isColorido(), getMarca() and getValor() return values of different types?

  • int, Boolean, String and float are the values, the idea would store side by side to print the line with information or at least display them side by side

  • @Brunomelo Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site

1 answer

2

The mistake is that the method add() only accepts one argument and you are trying to use several. This is the error, so using one will work. I know it’s not what you want, but it’s what you can answer. Probably want to do something else there, talabvez create an object and put in this array.

I’m sorry it’s not what you want to see, but it’s the best I can do. Solving this problem doesn’t do much good. The amount of errors in this code is huge and is learning a lot wrong, so it’s even better that it doesn’t work.

I cannot list all the mistakes and some can only speculate by not knowing the requirements, but you can infer something by what is universally done.

This heritage does not seem to make sense, a Pedido is not a Manipulacao whatever this means. If you don’t understand what inheritance is for, don’t try to do it.

Those arrays in this class do not seem to make even more sense without using generic syntax. No real request would have these fixed things, it’s a wrong modeling, so I say don’t even worry about the error presented, it only exists because the class is already conceptually wrong and fixing these errors the question error will no longer exist. The same goes for customer creation.

This class that creates date is certainly an error, you can already see by the way the constructor was done, prefer to use what you have ready.

float cannot be used for money. It makes no sense to create an empty constructor that does nothing, the identifier names are bad, the methods don’t seem to do what their names indicate.

  • It’s about a college job, how I’m learning I didn’t imagine it had so many meaningless things, but the way the job was proposed was really horrible. Thanks for the help, I know also that I can not base myself on this code to do anything hahaha

  • implement an interface can be called inheritance ?

  • @Gustavo https://answall.com/q/152266/101

Browser other questions tagged

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