How to receive by parameter an array of objects of another class in Java?

1

Hello everyone, my question is that I am trying to get an array of objects from another class, by parameter, to the class I want to put the array by parameter.

The classes are: Course and Costs

I have to get by parameter an array of objects of the type Route, to then be able to calculate. Here is the code:

Class Path :

public class Percurso {

    private double kmPercorrida;
    private double valorCombustivel;
    private double valorPedagio;

    public Percurso() {
        this(0,0,0);
    }

    public Percurso(double kmPercorrida, double valorCombustivel,
            double valorPedagio) {

        this.kmPercorrida = kmPercorrida;
        this.valorCombustivel = valorCombustivel;
        this.valorPedagio = valorPedagio;
    }

Class Costs :

public class Custos {

    public String calcularViagem(Percurso [] p ) {



        return "";


    }

}

In the Route [] p part, I need to pass the Route object array, with the variables kmPercubage, FuelValue, PagerPage .

NOTE: In the return I just left so no problems appear, then I change.

How can I do this? If anyone knows please help me. And sorry if the format of the post is wrong, I'm new here in the forum. I've also read how to make a decent post but still any mistake, please let me know what I'll do.

    
asked by anonymous 19.03.2016 / 04:21

2 answers

1
public class Custos {

  public String calcularViagem(Percurso[] percursos) {
  return "";
  }

}
    
19.03.2016 / 05:24
1

To declare an array in Java would be Percurso[] p , not Percurso p[] .

    
19.03.2016 / 04:50