i have tried this question in a different way....is it correct??...but there are some mistakes due to which i am not getting the output.....it would be great if you could point out to me...
package module4a;
class Passenger{
String name;
int age;
char gender;
int weight;
public Passenger(){
}
public Passenger(String name,int age,char gender,int weight){
this.name = name;
this.weight = weight;
Passenger passengers3 = new Passenger("A",23,'F',45);
Passenger passengers1 = new Passenger("B",13,'M',55);
Passenger passengers2 = new Passenger("C",33,'M',65);
Passenger[] passengers = {passengers3,passengers1,passengers2};
}
}
class Train {
public int total(Passenger[] passengers) {
Passenger object = new Passenger();
int total =0;
for(int i=0;i<passengers.length;i++){
total = total+object.weight;
}
System.out.println(total);
return total;
}
}
public class TestTrain {
public static void main(String[] args) {
// TODO Auto-generated method stub
Train test = new Train();
System.out.println();
}
}